<div dir="ltr"><div>After converting to GeoJSON the next step is saving the json into a MongoDB database. The customer I work for has chosen to store all GIS-data in GeoJSON in a nosql database like MongoDB. <br></div><div><br></div><div>That's why I would prefer not creating a file just to get hold of the json after importing and transforming the original data using GDAL. In the future we're thinking of supporting more formats than ESRI Shapefile and GeoJSON as input.</div><div><br></div><div>Hope this explains my question.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Den ons 11 nov. 2020 kl 12:34 skrev Paul Harwood <<a href="mailto:runette@gmail.com">runette@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I have a working c# GDAL app - I might be able to help.</div><div><br></div><div>I am not sure I understand what you are trying to do? It looks like you are creating a GeoJSON file from a shapefile and that actually only makes any sense if you want to save the file?</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br><br></div><div> <i> private FeatureCollection ImportShapeFile(IEnumerable<ImportFile> files)<br> {<br> var tempJsonFilename = $"/vsimem/temp.json";<br><br> GdalConfiguration.ConfigureGdal();<br> GdalConfiguration.ConfigureOgr();<br><br> try<br> {<br><br> // Copy into GDAL<br> foreach (var file in files)<br> {<br> Gdal.FileFromMemBuffer($"/vsimem/{file.Filename}", file.Data);<br> }</i></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><i> // Load shape<br> var shpDriver = Ogr.GetDriverByName("ESRI Shapefile");<br> var shpFile = files.First(f => f.Filename.EndsWith(".shp"));<br> var shpDatasource = Ogr.Open($"/vsimem/{shpFile.Filename}", 0);<br> if (shpDatasource == null)<br> return null;<br><br> var shpLayer = shpDatasource.GetLayerByIndex(0);<br><br> // Setup projection transform to WGS84<br> var srcProjection = shpLayer.GetSpatialRef();<br> var destProjection = new SpatialReference("");<br> destProjection.ImportFromEPSG(4326);<br> var transform = new CoordinateTransformation(srcProjection, destProjection);<br><br> // Copy layer to geo json<br> var jsonDriver = Ogr.GetDriverByName("GeoJSON");<br> var jsonDataSource = jsonDriver.CreateDataSource(tempJsonFilename, new string[] { });<br> var jsonLayer = jsonDataSource.CreateLayer(shpLayer.GetName(), destProjection, shpLayer.GetGeomType(), new string[] { });<br><br> var shpFeature = shpLayer.GetNextFeature();<br> while (shpFeature != null)<br> {<br> // Transform geometry<br> var geometry = shpFeature.GetGeometryRef();<br> geometry.Transform(transform);<br><br> // Save feature to new layer<br> jsonLayer.CreateFeature(shpFeature);<br><br> shpFeature = shpLayer.GetNextFeature();<br> }<br><br> // TODO: HERE I would like to read the information from my tempJsonFile back into a byte array, before unlinking.<br> var jsonBuffer = new byte[0];<br><br> // Close all GDAL stuff<br> jsonLayer.Dispose();<br> jsonDataSource.Dispose();<br> jsonDriver.Dispose();<br> shpLayer.Dispose();<br> shpDatasource.Dispose();<br> shpDriver.Dispose();<br><br> // Read json from buffer<br> var jsonText = Encoding.UTF8.GetString(jsonBuffer, 0, jsonBuffer.Length); ;<br> var json = JsonConvert.DeserializeObject<FeatureCollection>(jsonText);<br><br> return json;<br> }<br> catch (Exception exception)<br> {<br> throw exception;<br> }<br> finally<br> {<br> // Clear files from GDAL<br> Gdal.Unlink(tempJsonFilename);<br> foreach (var file in files)<br> {<br> Gdal.Unlink($"/vsimem/{file.Filename}");<br> }<br> }<br> }</i><br></div><div><br></div><div><br></div><div>Best Regards</div><font color="#888888"><div>Christian</div></font><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><br><div><div style="font-size:13px"><b><font face="georgia, serif">Christian Sörensen</font></b></div><div><b><font face="georgia, serif" size="1">UX Productions AB</font></b></div><div style="color:rgb(136,136,136);font-size:13px"><div><font face="trebuchet ms, sans-serif"><font size="1"><a href="http://www.uxproductions.se" target="_blank">www.uxproductions.se</a> | <a href="mailto:christian@uxproductions.se" style="color:rgb(17,85,204)" target="_blank">christian@uxproductions.se</a> | </font><span style="font-size:x-small"><a value="+46702677212" style="color:rgb(17,85,204)">+46 (0)70 26 77 212</a> </span></font></div><div><span lang="EN-GB" style="font-size:13.5pt;font-family:Webdings;color:green">P</span><span lang="EN-GB" style="font-size:11.5pt;font-family:Calibri,sans-serif;color:black"> </span><span style="font-size:7.5pt;font-family:Arial,sans-serif;color:green">Överväg miljöpåverkan innan du skriver ut detta e-postmeddelande</span></div></div></div></div></div></div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a></blockquote></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><br><div><div style="font-size:13px"><b><font face="georgia, serif">Christian Sörensen</font></b></div><div><b><font face="georgia, serif" size="1">UX Productions AB</font></b></div><div style="color:rgb(136,136,136);font-size:13px"><div><font face="trebuchet ms, sans-serif"><font size="1"><a href="http://www.uxproductions.se" target="_blank">www.uxproductions.se</a> | <a href="mailto:christian@uxproductions.se" style="color:rgb(17,85,204)" target="_blank">christian@uxproductions.se</a> | </font><span style="font-size:x-small"><a value="+46702677212" style="color:rgb(17,85,204)">+46 (0)70 26 77 212</a> </span></font></div><div><span lang="EN-GB" style="font-size:13.5pt;font-family:Webdings;color:green">P</span><span lang="EN-GB" style="font-size:11.5pt;font-family:Calibri,sans-serif;color:black"> </span><span style="font-size:7.5pt;font-family:Arial,sans-serif;color:green">Överväg miljöpåverkan innan du skriver ut detta e-postmeddelande</span></div></div></div></div></div>