سؤال

I have a function where the user uploads a KML file, I use XSLT to convert it to GML and then save it to another file. My question is how can I import this GML data to the geometry column using GeomFromGML() in MVC?

Totally stumped and can't find any good examples. Below is my code for the upload and transformation:

var fileName = Path.GetFileName(Polygon.FileName);
                var path = Path.Combine(Server.MapPath("~/App_Data/uploads"),fileName);
                Polygon.SaveAs(path);
                XPathDocument myXPathDoc = new XPathDocument(path);
                XslCompiledTransform myXslTrans = new XslCompiledTransform();
                myXslTrans.Load(Server.MapPath("~/App_Data/XSL/kml2gml2.xsl"));
                var gml = Path.Combine(Server.MapPath("~/App_Data/GML/gml.xml"));
                XmlTextWriter myWriter = new XmlTextWriter(gml, null);
                myXslTrans.Transform(myXPathDoc, null, myWriter);
هل كانت مفيدة؟

المحلول

I never had any luck with the GeomFromGML() so instead I use the NetTopologySuite. It contains two classes: GMLReader and WKTWriter that you can use to first read the GML and then write it to WKT. The WKT can be inserted into the database using the STGeomFromtext to save it in your SQL Database:

GMLReader gmlr = new GMLReader();
WKTWriter wktw = new WKTWriter();
IGeometry g = gmlr.Read(gmlxml);
string wkt = wktw.Write(g);
string sql = "INSERT INTO mytable (GeomCol) VALUES (geometry::STGeomFromText('"+wkt+"', 0));";

Or perhaps your XSLT can be used to transform the KML directly to WKT?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top