public static string Geometry2GML(IGeometry geometry, string srsName, GmlVersion version) { ISpatialReference sRef = (int)version > 2 ? SpatialReference.FromID(srsName) : null; if (geometry is IEnvelope) { return(Envelope2GML(geometry as IEnvelope, srsName, sRef)); } else if (geometry is IPoint) { return(Point2GML(geometry as IPoint, srsName, sRef)); } else if (geometry is IPolyline) { return(Polyline2GML(geometry as IPolyline, srsName, sRef)); } else if (geometry is IPolygon) { return(Polygon2GML(geometry as IPolygon, srsName, sRef)); } else if (geometry is IAggregateGeometry) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < ((IAggregateGeometry)geometry).GeometryCount; i++) { sb.Append(Geometry2GML(((IAggregateGeometry)geometry)[i], srsName, version)); } return(sb.ToString()); } return(""); }
public FeatureCursor(IFeatureClass fc, XmlNode featureCollection, XmlNamespaceManager ns, IQueryFilter filter, GmlVersion gmlVersion) : base((fc != null) ? fc.SpatialReference : null, (filter != null) ? filter.FeatureSpatialReference : null) { _ns = ns; _filter = filter; _fc = fc; _gmlVersion = gmlVersion; if (featureCollection == null || ns == null || fc == null) { return; } try { _features = featureCollection.SelectNodes("GML:featureMember/myns:" + XML.Globals.TypeWithoutPrefix(fc.Name), ns); } catch { _features = null; } }
public FeatureCursor2(IFeatureClass fc, XmlTextReader reader, XmlNamespaceManager ns, IQueryFilter filter, GmlVersion gmlVersion) : base((fc != null) ? fc.SpatialReference : null, (filter != null) ? filter.FeatureSpatialReference : null) { _ns = ns; _filter = filter; _fc = fc; _gmlVersion = gmlVersion; if (reader == null || ns == null || fc == null) { return; } try { _reader = reader; } catch { _reader = null; } }
public static bool Create(string filename, IGeometryDef geomDef, Fields fields, GmlVersion gmlVersion) { try { FileInfo fi = new FileInfo(filename); string name = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length); string gml_filename = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".gml"; string xsd_filename = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".xsd"; FeatureClass featureClass = new FeatureClass(null, name, fields); XmlSchemaWriter schemaWriter = new XmlSchemaWriter(featureClass); string schema = schemaWriter.Write(); using (StreamWriter sw = new StreamWriter(xsd_filename, false, Encoding.UTF8)) { sw.WriteLine(schema.Trim()); sw.Flush(); sw.Close(); } using (StreamWriter sw = new StreamWriter(gml_filename, false, Encoding.UTF8)) { sw.Write(@"<?xml version=""1.0"" encoding=""UTF-8""?> <gml:FeatureCollection xmlns:gml=""http://www.opengis.net/gml"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:gv=""http://www.gViewGIS.com/server"" xsi:schemaLocation=""http://www.gview.com/gml " + name + @".xsd"">".Trim()); string boundingBox = GeometryTranslator.Geometry2GML(new Envelope(), String.Empty, gmlVersion); sw.WriteLine(@" <gml:boundedBy>"); sw.Write(boundingBox); sw.Write(@" </gml:boundedBy>"); sw.Write(@" </gml:FeatureCollection>"); sw.Flush(); sw.Close(); } return(true); } catch { return(false); } }
public FeatureCursor(IFeatureClass fc, XmlNode featureCollection, XmlNamespaceManager ns, IQueryFilter filter, GmlVersion gmlVersion, Filter_Capabilities filterCapabilities) : this(fc, featureCollection, ns, filter, gmlVersion) { // // wenn Filter schon geometry operation implementiert // ist es hier nicht noch einmal zu vergleichen... // if (filterCapabilities != null && _filter is ISpatialFilter && filterCapabilities.SupportsSpatialOperator(((ISpatialFilter)_filter).SpatialRelation)) { _checkGeometryRelation = false; } }
public static void Features2GML(IFeatureCursor cursor, IFeatureClass fc, string fcID, StringBuilder sb, string srsName, IGeometricTransformer transformer, GmlVersion version, int maxFeatures) { if (cursor == null || fc == null) { return; } int count = 0; IFeature feature = null; while ((feature = cursor.NextFeature) != null) { Feature2GML(feature, fc, fcID, sb, srsName, transformer, version); count++; if (maxFeatures > 0 && count > maxFeatures) { break; } } }
public static void Features2GML(IFeatureCursor cursor, IFeatureClass fc, string fcID, StringBuilder sb, string srsName, IGeometricTransformer transformer, GmlVersion version) { Features2GML(cursor, fc, fcID, sb, srsName, transformer, version, -1); }
public static void Feature2GML(IFeature feature, IFeatureClass fc, string fcID, StringBuilder sb, string srsName, IGeometricTransformer transformer, GmlVersion version) { if (feature == null || fc == null) { return; } sb.Append(@" <gml:featureMember> <gv:" + fcID + " gml:id=\"" + fcID + "." + feature.OID + "\">"); // Shape IGeometry shape = (transformer != null) ? transformer.Transform2D(feature.Shape) as IGeometry : feature.Shape; if (shape != null) { sb.Append(@" <gml:boundedBy>"); sb.Append(GeometryTranslator.Geometry2GML(shape.Envelope, srsName, version)); sb.Append(@" </gml:boundedBy>"); sb.Append(@" <gv:" + fc.ShapeFieldName.Replace("#", "") + ">"); sb.Append(GeometryTranslator.Geometry2GML(shape, srsName, version)); sb.Append(@" </gv:" + fc.ShapeFieldName.Replace("#", "") + ">"); } // Fields foreach (FieldValue fv in feature.Fields) { if (fv.Name == fc.ShapeFieldName) { continue; } // TODO: Value soll noch auf <,>,&,... untersucht werden !!! sb.Append(@" <gv:" + fv.Name.Replace("#", "") + ">" + fv.Value + "</gv:" + fv.Name.Replace("#", "") + ">"); } sb.Append(@" </gv:" + fcID + @"> </gml:featureMember>"); }
public static IGeometry GML2Geometry(string gml, GmlVersion gmlVersion) { try { gml = gml.Replace("<gml:", "<").Replace("</gml:", "</"); XmlDocument doc = new XmlDocument(); doc.LoadXml(gml); XmlNode geomNode = doc.ChildNodes[0]; ISpatialReference sRef = null; if ((int)gmlVersion > 2 && geomNode.Attributes["srsName"] != null) { sRef = SpatialReference.FromID(geomNode.Attributes["srsName"].Value); } switch (geomNode.Name) { case "Point": return(GML2Point(geomNode, sRef)); case "pointProperty": return(GML2Point(geomNode.SelectSingleNode("Point"), sRef)); case "Box": case "Envelope": return(GML2Envelope(geomNode, sRef)); case "LineString": IPath path = GML2Path(geomNode, sRef); if (path == null) { return(null); } Polyline polyline = new Polyline(); polyline.AddPath(path); return(polyline); case "MultiLineString": return(GML2Polyline(geomNode, sRef)); case "curveProperty": return(GML2Polyline(geomNode, sRef)); case "Polygon": return(GML2Polygon(geomNode, sRef)); case "MultiPolygon": AggregateGeometry aGeom1 = new AggregateGeometry(); foreach (XmlNode polygonNode in geomNode.SelectNodes("polygonMember/Polygon")) { IPolygon polygon = GML2Polygon(polygonNode, sRef); if (polygon != null) { aGeom1.AddGeometry(polygon); } } if (aGeom1.GeometryCount == 0) { return(null); } IPolygon mpolygon1 = (IPolygon)aGeom1[0]; for (int i = 1; i < aGeom1.GeometryCount; i++) { IPolygon p = (IPolygon)aGeom1[i]; for (int r = 0; r < p.RingCount; r++) { mpolygon1.AddRing(p[r]); } } return(mpolygon1); case "surfaceProperty": AggregateGeometry aGeom2 = new AggregateGeometry(); foreach (XmlNode polygonNode in geomNode.SelectNodes("Surface/patches/PolygonPatch")) { IPolygon polygon = GML2Polygon(polygonNode, sRef); if (polygon != null) { aGeom2.AddGeometry(polygon); } } if (aGeom2.GeometryCount == 0) { return(null); } IPolygon mpolygon2 = (IPolygon)aGeom2[0]; for (int i = 1; i < aGeom2.GeometryCount; i++) { IPolygon p = (IPolygon)aGeom2[i]; for (int r = 0; r < p.RingCount; r++) { mpolygon2.AddRing(p[r]); } } return(mpolygon2); default: return(null); } } catch (Exception ex) { string err = ex.Message; return(null); } }
static public string Create(IFeatureClass fc, string typeName, IQueryFilter filter, string srsName, Filter_Capabilities filterCapabilites, GmlVersion version) { MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms, Encoding.UTF8); sw.WriteLine( @"<?xml version=""1.0"" ?> <wfs:GetFeature version=""1.0.0"" service=""WFS"" maxfeatures=""5000"" handle=""gView Query"" xmlns=""http://www.opengis.net/wfs"" xmlns:wfs=""http://www.opengis.net/wfs"" xmlns:ogc=""http://www.opengis.net/ogc"" xmlns:gml=""http://www.opengis.net/gml"" xmlns:gv=""http://www.gview.com/server"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd""> <wfs:Query typeName=""" + typeName + @"""" + ((srsName != String.Empty) ? " srsName=\"" + srsName + "\"" : "") + " >"); if (filter.SubFields != "*" && filter.SubFields != "#ALL#") { foreach (string field in filter.SubFields.Split(' ')) { sw.Write("<wfs:PropertyName>" + field + "</wfs:PropertyName>"); } } else { foreach (IField field in fc.Fields) { sw.Write("<wfs:PropertyName>" + field.name + "</wfs:PropertyName>"); } } sw.WriteLine(Filter.ToWFS(fc, filter, filterCapabilites, version)); sw.WriteLine( @"</wfs:Query> </wfs:GetFeature>"); sw.Flush(); ms.Position = 0; byte[] bytes = new byte[ms.Length]; ms.Read(bytes, 0, (int)ms.Length); sw.Close(); string ret = Encoding.UTF8.GetString(bytes).Trim(); return(ret); }