Spatial Datatype (geometry) to GeoJSON

后端 未结 3 1774
醉话见心
醉话见心 2021-02-09 05:21

I want to convert geom (geometry) datatype to GeoJSON. How could I do that?

For example, the geometry in WKT:

    POLYGON((4552         


        
3条回答
  •  情深已故
    2021-02-09 05:43

    I think, you can produce geojson at server side when you get data from Sql Server.

    You should examine GeoJSON.Net and similar question

    var modelF = new List();
    foreach (DataRow dr in ds.Tables[0].Rows)
         {
           var point = new GeoJSON.Net.Geometry.Point(new GeoJSON.Net.Geometry.GeographicPosition(Convert.ToDouble(dr["latitude"].ToString()), Convert.ToDouble(dr["longitude"].ToString())));
           var featureProperties = new Dictionary { };
           foreach (DataColumn dataColumn in ds.Tables[0].Columns)
                {
                  featureProperties.Add(dataColumn.ColumnName, dr[dataColumn].ToString());
                }
           modelF.Add(new GeoJSON.Net.Feature.Feature(point, featureProperties));
         }
    var fcol = new FeatureCollection(modelF);
    var serializedData = JsonConvert.SerializeObject(fcol, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore });
    return serializedData;
    

    have a goo day.

提交回复
热议问题