jbrwn / NET-Mapnik

.NET bindings for mapnik
34 stars 12 forks source link

Registering DataSources in the DatsourceCache #13

Closed jskulavik closed 9 years ago

jskulavik commented 9 years ago

Thanks again for all of the help @jbrwn.

I'm successfully loading NETMapnik into x64 .NET 4.5.1 now, but running into the exception:

Could not create datasource for type: 'csv' (no datasource plugin directories have been successfully registered)

With both ".\mapnik\input" and "C:\mapnik-v2.2.0\lib\mapnik\input" supplied to DatasourceCache.RegisterDatasources then subsequently trying to instantiate a csv plugin.

            JObject geojson = JObject.Parse(mapData);
            DatasourceCache.RegisterDatasources(@".\mapnik\input");
            Dictionary<string, object> options = new Dictionary<string, object>()
            {
                { "type","csv"},
                { "inline", "geojson\n'" + geojson["geometry"].ToString(Formatting.None) + "'" }
            };

            Datasource ds = new Datasource(options);
jbrwn commented 9 years ago

Looks like that should work if you installed via the nuget packages.

"C:\mapnik-v2.2.0\lib\mapnik\input"

That is definitely not going to work. NETMapnik targets mapnik-sdk v3.0. Loading plugins from a previous version will not work.

There is not really a ton for me to go off here. I'd like to help but there is not much i can do unless you post a full working test case. For example, Here is a quick test case i set up too check your code:

  • create a new vs2015 console application targeting .NET 4.5.1
  • set platform target to x64
  • add mapnik.x64.1.0.0 nuget package
  • add Newtonsoft.Json.6.0.8 nuget package
  • run this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NETMapnik;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = @"{
                type: ""Feature"",
                properties: {},
                geometry: {
                    type: ""Polygon"",
                    coordinates: [[[1,1],[1,2],[2,2],[2,1],[1,1]]]
                }
            }";
            JObject geojson = JObject.Parse(input);
            DatasourceCache.RegisterDatasources(@".\mapnik\input");
            Dictionary<string, object> options = new Dictionary<string, object>()
            {
                { "type","csv"},
                { "inline", "geojson\n'" + geojson["geometry"].ToString(Formatting.None) + "'" }
            };

            Datasource ds = new Datasource(options);
            Console.ReadLine();
        }
    }
}

This compiles and executes without error

lsy8qh commented 5 years ago

image image not found DatasourceCache!! why?