public void Execute(IPlatformFactory factory, ITestLogger logger) { var wkt = new MgWktReaderWriter(); MgPoint geom1 = wkt.Read("POINT XY (1.0 1.0)") as MgPoint; MgPoint geom2 = wkt.Read("POINT XY (2.0 2.0)") as MgPoint; MgPoint geom3 = wkt.Read("POINT XY (1.0 1.0)") as MgPoint; MgPointCollection coll = new MgPointCollection(); coll.Add(geom1); coll.Add(geom2); coll.Add(geom3); Assert.AreEqual(3, coll.Count); Assert.IsTrue(geom1.Equals(coll[0])); Assert.IsTrue(coll[0].Equals(coll[2])); Assert.IsFalse(coll[0].Equals(coll[1])); coll[0] = coll[1]; Assert.IsTrue(coll[0].Equals(coll[1])); double x = 0.0; foreach (MgPoint geom in coll) { x += geom.GetCoordinate().GetX(); } Assert.AreEqual(5.0, x); }
private void AddRectangle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded) { _viewer.DigitizeRectangle((x1, y1, x2, y2) => { string text = string.Empty; if (retrieveTextMethod != null) { text = retrieveTextMethod(); } MgGeometry geom = _wktRW.Read(Util.MakeWktPolygon(x1, y1, x2, y2)); InsertRedlineGeometry(text, geom, onRedlineAdded); }); }
private void btnSelectCircle_Click(object sender, EventArgs e) { mgMapViewer1.DigitizeCircle((x, y, r) => { MgGeometry geom = _wktRw.Read(MakeWktCircle(x, y, r)); mgMapViewer1.SelectByGeometry(geom); }); }
private void btnRectangle_Click(object sender, EventArgs e) { _viewer.DigitizeRectangle((llx, lly, urx, ury) => { ClearFilterGeometry(); _filterGeometry = _wktRw.Read(Util.MakeWktPolygon(llx, lly, urx, ury)); lblSpatialFilterGeomSet.Visible = true; }); }
string pointTransformAndWriteZ(string geom, MgMap map) { double[] x = new double[1]; double[] y = new double[1]; double[] z = new double[1]; MgWktReaderWriter wktrwdmr = new MgWktReaderWriter(); MgPoint cntr = wktrwdmr.Read(geom).Centroid; x[0] = cntr.Coordinate.X; y[0] = cntr.Coordinate.Y; z[0] = 0; StringBuilder output = new StringBuilder(); output.Append("<table width=\"100%\" class=\"results\">"); //WGS preko MG API MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory(); string wktFrom = map.GetMapSRS(); string wktTo = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]"; MgCoordinateSystem CSSource = fact.Create(wktFrom); MgCoordinateSystem CSTarget = fact.Create(wktTo); MgCoordinateSystemTransform coordTransform = fact.GetTransform(CSSource, CSTarget); MgGeometryFactory geomFact = new MgGeometryFactory(); // GK //samo prvo višino zaenkrat, dokler ni enačbe za Z output.Append(String.Format("<tr><td class='header'><b>Map koordinates:</b></td><td class=\"results\"><table><tr><td><b>Y:</b></td><td>{0}</td></tr><tr><td><b>X:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.0}", x[0]), string.Format("{0:0.0}", y[0]))); int i = 0; //transformacija preko MG koordinatnega sistema foreach (double pointX in x) { MgCoordinate coord = geomFact.CreateCoordinateXY(x[i], y[i]); coord = coordTransform.Transform(coord); x[i] = coord.X; y[i] = coord.Y; i++; } double[] xwgs = x; double[] ywgs = y; output.Append(String.Format("<tr><td class='header'><b>WGS84:</b></td><td class=\"results\"><table><tr><td><b>Lon:</b></td><td>{0}</td></tr><tr><td><b>Lat:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.000000}", xwgs[0]), string.Format("{0:0.000000}", ywgs[0]))); output.Append("</table>"); return(output.ToString()); }
public void Execute(IPlatformFactory factory, ITestLogger logger) { var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService); var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService); var root = "../../TestData/TileService/"; Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs"); Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf"); Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf"); Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs"); Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf"); Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf"); Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs"); Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf"); Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf"); Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf"); var mdfId = new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition"); //This is a sample request from the AJAX viewer. It selected 7 features. It should do the same here. var dpi = 96; var width = 773; var height = 696; var scale = 4345.697945713148; var x = -87.72117757411266; var y = 43.7527161153258; var wkt = "POLYGON((-87.72250482778884 43.75497812742761, -87.72134799968197 43.75497812742761, -87.72134799968197 43.75358373640595, -87.72250482778884 43.75358373640595, -87.72250482778884 43.75497812742761))"; var map = (MgMap)factory.CreateMap(mdfId, mdfId.Name, width, height, x, y, scale, dpi); var wktRw = new MgWktReaderWriter(); var geom = wktRw.Read(wkt); var layerNames = new MgStringCollection(); layerNames.Add("Parcels"); var result = renderSvc.QueryFeatures(map, layerNames, geom, MgFeatureSpatialOperations.Intersects, -1); var sel = result.GetSelection(); sel.SetMap(map); var total = 0; var selLayers = sel.GetLayers(); foreach (var sl in selLayers) { total += sel.GetSelectedFeaturesCount(sl, sl.FeatureClassName); } Assert.AreEqual(7, total); }
// GET: Search/Results public ActionResult Results(SearchInputModel input) { MgSiteConnection conn = CreateConnection(input); MgMap map = new MgMap(conn); map.Open(input.MapName); MgLayerCollection layers = map.GetLayers(); int lidx = layers.IndexOf("Parcels"); if (lidx < 0) { throw new Exception("Layer not found on map: Parcels"); } MgLayerBase layer = layers[lidx]; MgFeatureQueryOptions query = new MgFeatureQueryOptions(); //Don't fret about the input here. This is not a SQL injection attack vector. This filter string is //not SQL, it's a FDO filter. A 'DROP TABLE' or any other destructive SQL will fail on //query execution when this filter is parsed to a FDO filter. switch (input.By) { case "OWNER": query.SetFilter("RNAME LIKE '%" + input.Query.Replace("'", "\'") + "%'"); break; case "ADDRESS": query.SetFilter("RPROPAD LIKE '%" + input.Query.Replace("'", "\'") + "%'"); break; case "BBOX": double[] parts = input.Query.Split(',').Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); if (parts.Length != 4) { throw new Exception("Invalid BBOX parameter"); } MgWktReaderWriter wktRw = new MgWktReaderWriter(); MgGeometry filterGeom = wktRw.Read(MakeWktPolygon(parts[0], parts[1], parts[2], parts[3])); query.SetSpatialFilter(layer.FeatureGeometryName, filterGeom, MgFeatureSpatialOperations.Intersects); break; default: throw new Exception("Unknown query type: " + input.By); } SearchResultViewModel vm = new SearchResultViewModel(); vm.Session = input.Session; vm.MapName = input.MapName; vm.LoadResults(layer, query); return(View(vm)); }
void OnSelectRadius(object sender, EventArgs e) { if (_viewer == null) { return; } _viewer.DigitizeCircle((x, y, r) => { MgGeometry geom = _wktRw.Read(Util.MakeWktCircle(x, y, r, true)); _viewer.SelectByGeometry(geom); }); }
MgPropertyCollection MakePoint(String name, double x, double y, MgWktReaderWriter wktReaderWriter, MgAgfReaderWriter agfReaderWriter) { MgPropertyCollection propertyCollection = new MgPropertyCollection(); MgStringProperty nameProperty = new MgStringProperty("NAME", name); propertyCollection.Add(nameProperty); MgGeometry geometry = wktReaderWriter.Read("POINT XY (" + x + " " + y + ")"); MgByteReader geometryByteReader = agfReaderWriter.Write(geometry); MgGeometryProperty geometryProperty = new MgGeometryProperty("GEOM", geometryByteReader); propertyCollection.Add(geometryProperty); return(propertyCollection); }
public override void Invoke() { var viewer = this.Viewer; viewer.DigitizeCircle((x, y, r) => { if (_wktRw == null) { _wktRw = new MgWktReaderWriter(); } MgGeometry geom = _wktRw.Read(Util.MakeWktCircle(x, y, r, true)); viewer.SelectByGeometry(geom); }); }
// GET: Search/Results public ActionResult Results(SearchInputModel input) { MgSiteConnection conn = CreateConnection(input); MgMap map = new MgMap(conn); map.Open(input.MapName); MgLayerCollection layers = map.GetLayers(); int lidx = layers.IndexOf("Parcels"); if (lidx < 0) { throw new Exception("Layer not found on map: Parcels"); } MgLayerBase layer = layers.GetItem(lidx); MgFeatureQueryOptions query = new MgFeatureQueryOptions(); //Don't fret about the input here. This is not a SQL injection attack vector. This filter string is //not SQL, it's a FDO filter. A 'DROP TABLE' or any other destructive SQL will fail on //query execution when this filter is parsed to a FDO filter. switch (input.By) { case "OWNER": query.SetFilter("RNAME LIKE '%" + input.Query.Replace("'", "\'") + "%'"); break; case "ADDRESS": query.SetFilter("RPROPAD LIKE '%" + input.Query.Replace("'", "\'") + "%'"); break; case "BBOX": double[] parts = input.Query.Split(',').Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); if (parts.Length != 4) { throw new Exception("Invalid BBOX parameter"); } MgWktReaderWriter wktRw = new MgWktReaderWriter(); MgGeometry filterGeom = wktRw.Read(MakeWktPolygon(parts[0], parts[1], parts[2], parts[3])); query.SetSpatialFilter(layer.FeatureGeometryName, filterGeom, MgFeatureSpatialOperations.Intersects); break; default: throw new Exception("Unknown query type: " + input.By); } SearchResultViewModel vm = new SearchResultViewModel(); vm.Session = input.Session; vm.MapName = input.MapName; vm.LoadResults(layer, query); return View(vm); }
private void OnPointDrawn(double x, double y) { if (_pointLayer == null) //Our point layer doesn't exist { CreateRedlineLayer(); } //Now insert our point. This code should look familiar //to you, setting up the MgPropertyCollection for insertion MgPropertyCollection props = new MgPropertyCollection(); MgWktReaderWriter wktRw = new MgWktReaderWriter(); MgAgfReaderWriter agfRw = new MgAgfReaderWriter(); MgGeometry geom = wktRw.Read("POINT (" + x + " " + y + ")"); MgByteReader agf = agfRw.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf); props.Add(geomProp); //Here's where we differ from the official MapGuide API //instead of a monolithic UpdateFeatures() that tries to //do everything, we have individual InsertFeatures/DeleteFeatures/UpdateFeatures //methods. So here's the mg-desktop way MgFeatureReader result = _pointLayer.InsertFeatures(props); result.Close(); //Or if you have have access to the MgdLayer instance /* * MgResourceIdentifier fsId = new MgResourceIdentifier(_pointLayer.GetFeatureSourceId()); * MgServiceFactory factory = new MgServiceFactory(); * MgdFeatureService featSvc = (MgdFeatureService)factory.CreateService(MgServiceType.FeatureService); * MgFeatureReader fr = featSvc.InsertFeatures(fsId, "Default:Redline", props); * fr.Close(); */ //Now refresh to see your newly drawn point mgMapViewer1.RefreshMap(); }
public static void WellKnownText() { MgAgfReaderWriter agfReaderWriter; MgWktReaderWriter wktReaderWriter; MgPoint pt11FromText; MgPoint pt11; var pt11TextSpec = "POINT XY ( 1 1 )"; MgByteReader byteReader; string geometryAgfText; agfReaderWriter = new MgAgfReaderWriter(); wktReaderWriter = new MgWktReaderWriter(); // In the string to geometry direction: pt11FromText = wktReaderWriter.Read(pt11TextSpec) as MgPoint; byteReader = agfReaderWriter.Write(pt11FromText); // In the geometry to string direction: pt11 = (MgPoint)agfReaderWriter.Read(byteReader); geometryAgfText = wktReaderWriter.Write(pt11); // geometryAgfText now contains the text representation of the geometry }
//---------------------------------------------------------------------------------------- // �� �ܣ� ���ڴ�������ݣ�x��y�������ռ��Ҫ������ // // �� �ߣ� // // // �� �ڣ�2007.05.# // //----------------------------------------------------------------------------------------- public MgPropertyCollection MakePoint(string name, double x, double y) { MgPropertyCollection propertyCollection = new MgPropertyCollection(); MgStringProperty nameProperty = new MgStringProperty("NAME", name); propertyCollection.Add(nameProperty); MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter(); MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgGeometry geometry = wktReaderWriter.Read("POINT XY (" + x.ToString() + " " + y.ToString() + ")"); MgByteReader geometryByteReader = agfReaderWriter.Write(geometry); MgGeometryProperty geometryProperty = new MgGeometryProperty("GEOM", geometryByteReader); propertyCollection.Add(geometryProperty); return propertyCollection; }
private void OnPointDrawn(double x, double y) { if (_pointLayer == null) //Our point layer doesn't exist CreateRedlineLayer(); //Now insert our point. This code should look familiar //to you, setting up the MgPropertyCollection for insertion MgPropertyCollection props = new MgPropertyCollection(); MgWktReaderWriter wktRw = new MgWktReaderWriter(); MgAgfReaderWriter agfRw = new MgAgfReaderWriter(); MgGeometry geom = wktRw.Read("POINT (" + x + " " + y + ")"); MgByteReader agf = agfRw.Write(geom); MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf); props.Add(geomProp); //Here's where we differ from the official MapGuide API //instead of a monolithic UpdateFeatures() that tries to //do everything, we have individual InsertFeatures/DeleteFeatures/UpdateFeatures //methods. So here's the mg-desktop way MgFeatureReader result = _pointLayer.InsertFeatures(props); result.Close(); //Or if you have have access to the MgdLayer instance /* MgResourceIdentifier fsId = new MgResourceIdentifier(_pointLayer.GetFeatureSourceId()); MgServiceFactory factory = new MgServiceFactory(); MgdFeatureService featSvc = (MgdFeatureService)factory.CreateService(MgServiceType.FeatureService); MgFeatureReader fr = featSvc.InsertFeatures(fsId, "Default:Redline", props); fr.Close(); */ //Now refresh to see your newly drawn point mgMapViewer1.RefreshMap(); }
public override string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions) { string runtimeMapName = rtMap.Name; MgRenderingService rs = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgMap map = new MgMap(); string mapname = runtimeMapName.IndexOf(":") > 0 ? new ResourceIdentifier(runtimeMapName).Path : runtimeMapName; map.Open(res, mapname); MgWktReaderWriter r = new MgWktReaderWriter(); MgStringCollection layerNames = null; string featureFilter = ""; int layerAttributeFilter = 0; int op = MgFeatureSpatialOperations.Intersects; if (selectionVariant == "TOUCHES") op = MgFeatureSpatialOperations.Touches; else if (selectionVariant == "INTERSECTS") op = MgFeatureSpatialOperations.Intersects; else if (selectionVariant == "WITHIN") op = MgFeatureSpatialOperations.Within; else if (selectionVariant == "ENVELOPEINTERSECTS") op = MgFeatureSpatialOperations.EnvelopeIntersects; else throw new ArgumentException("Unknown or unsupported selection variant: " + selectionVariant); if (extraOptions != null) { if (!string.IsNullOrEmpty(extraOptions.FeatureFilter)) featureFilter = extraOptions.FeatureFilter; if (extraOptions.LayerNames != null && extraOptions.LayerNames.Length > 0) { layerNames = new MgStringCollection(); foreach (var name in extraOptions.LayerNames) layerNames.Add(name); } layerAttributeFilter = (int)extraOptions.LayerAttributeFilter; } MgFeatureInformation info = rs.QueryFeatures(map, layerNames, r.Read(wkt), op, featureFilter, maxFeatures, layerAttributeFilter); string xml = ""; GetByteReaderMethod fetch = () => { return info.ToXml(); }; using (var sr = new StreamReader(new MgReadOnlyStream(fetch))) { xml = sr.ReadToEnd(); } //We only want the FeatureSet element var doc = new System.Xml.XmlDocument(); doc.LoadXml(xml); xml = doc.DocumentElement["FeatureSet"].OuterXml; MgSelection sel = new MgSelection(map, xml); sel.Save(res, mapname); LogMethodCall("QueryMapFeatures", true, runtimeMapName, wkt, persist, selectionVariant, extraOptions == null ? "null" : "QueryMapOptions"); return xml; }
public static MgByteReader GetAgf(IGeometry geom) { MgGeometry mgeom = _wktRw.Read(geom.AsText()); return(_agfRw.Write(mgeom)); }
string pointTransformAndWriteZ(string geom, MgMap map) { double[] x = new double[1]; double[] y = new double[1]; double[] z = new double[1]; MgWktReaderWriter wktrwdmr = new MgWktReaderWriter(); MgPoint cntr = wktrwdmr.Read(geom).Centroid; x[0] = cntr.Coordinate.X; y[0] = cntr.Coordinate.Y; z[0] = 0; StringBuilder output = new StringBuilder(); output.Append("<table width=\"100%\" class=\"results\">"); //WGS preko MG API MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory(); string wktFrom = map.GetMapSRS(); string wktTo = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]"; MgCoordinateSystem CSSource = fact.Create(wktFrom); MgCoordinateSystem CSTarget = fact.Create(wktTo); MgCoordinateSystemTransform coordTransform = fact.GetTransform(CSSource, CSTarget); MgGeometryFactory geomFact = new MgGeometryFactory(); // GK //samo prvo višino zaenkrat, dokler ni enačbe za Z output.Append(String.Format("<tr><td class='header'><b>Map koordinates:</b></td><td class=\"results\"><table><tr><td><b>Y:</b></td><td>{0}</td></tr><tr><td><b>X:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.0}", x[0]), string.Format("{0:0.0}", y[0]))); int i = 0; //transformacija preko MG koordinatnega sistema foreach (double pointX in x) { MgCoordinate coord = geomFact.CreateCoordinateXY(x[i], y[i]); coord = coordTransform.Transform(coord); x[i] = coord.X; y[i] = coord.Y; i++; } double[] xwgs = x; double[] ywgs = y; output.Append(String.Format("<tr><td class='header'><b>WGS84:</b></td><td class=\"results\"><table><tr><td><b>Lon:</b></td><td>{0}</td></tr><tr><td><b>Lat:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.000000}", xwgs[0]), string.Format("{0:0.000000}", ywgs[0]))); output.Append("</table>"); return output.ToString(); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string sessionId = GetRequestParameters(Request)["SESSION"]; string mapName = GetRequestParameters(Request)["MAPNAME"]; string locale = GetRequestParameters(Request)["LOCALE"]; if (string.IsNullOrEmpty(sessionId)) { Response.Clear(); Response.End(); return; } if (string.IsNullOrEmpty(mapName)) { Response.Clear(); Response.End(); return; } MgResourceService resourceSrvc = GetMgResurceService(sessionId); MgFeatureService featureSrvc = GetMgFeatureService(sessionId); MgMap map = new MgMap(); map.Open(resourceSrvc, mapName); string layernames = GetRequestParameters(Request)["LAYERNAMES"]; string GEOMETRY = GetRequestParameters(Request)["GEOMETRY"]; string selVar = GetRequestParameters(Request)["SELECTIONVARIANT"]; string type = GetRequestParameters(Request)["tp"]; string inputSel = GetRequestParameters(Request)["SELECTION"]; bool hasInputGeom = false; if (!string.IsNullOrEmpty(GEOMETRY)) { hasInputGeom = true; } //selection ima prednost pred podano geometrijo ... MgWktReaderWriter wktrw = new MgWktReaderWriter(); if (!string.IsNullOrEmpty(inputSel)) { MgGeometry inputGeom = MultiGeometryFromSelection(featureSrvc, map, inputSel); GEOMETRY = wktrw.Write(inputGeom); } MgAgfReaderWriter agfRW = new MgAgfReaderWriter(); int nLayer = 0; // pobrišem in zgradim na novo samo tiste, ki imajo zadetke ... int nSloj = 0; string filter = ""; StringBuilder sbOut = new StringBuilder(); sbOut.Append("<table width=\"100%\" class=\"results\">"); sbOut.Append("<tr><td class='header'></td><td class='header'>" + "Layer" + "</td><td class='header' align=\"center\">" + "Select" + "</td><td class='header' align=\"center\">" + "Report" + "</td></tr>"); MgSelection selAll = new MgSelection(map); foreach (MgLayer layer in map.GetLayers()) { if (type != "2") { if (!layer.IsVisible()) { goto nextlay; } } if (layer.LegendLabel == "") { goto nextlay; } try { nLayer++; filter = String.Format("{0} {1} GeomFromText('{2}')", layer.GetFeatureGeometryName(), selVar, GEOMETRY); //preveriti še filter na Layerju. Ker ne gre drugače, je potrebno pogledati v XML MgResourceIdentifier layerDefResId = layer.GetLayerDefinition(); MgByteReader byteReader = resourceSrvc.GetResourceContent(layerDefResId); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); String xmlLayerDef = byteReader.ToString(); doc.LoadXml(xmlLayerDef); KALI.MGE.Objects.KALILayerDefinition.LayerDefinition ld = KALI.MGE.Objects.KALILayerDefinition.LayerDefinition.Parse(xmlLayerDef); if (!string.IsNullOrEmpty(ld.VectorLayerDefinition.Filter)) { filter += " AND (" + ld.VectorLayerDefinition.Filter + ")"; } //query the features MgFeatureQueryOptions opts = new MgFeatureQueryOptions(); opts.SetFilter(filter); String featureClassName = layer.GetFeatureClassName(); MgResourceIdentifier srcId = new MgResourceIdentifier(layer.GetFeatureSourceId()); MgFeatureReader features = featureSrvc.SelectFeatures(srcId, featureClassName, opts); bool hasResult = features.ReadNext(); if (hasResult) { nSloj++; int n = 0; MgClassDefinition classDef = features.GetClassDefinition(); MgPropertyDefinitionCollection classDefProps = classDef.GetIdentityProperties(); ArrayList idPropNames = new ArrayList(classDefProps.GetCount()); for (int j = 0; j < classDefProps.GetCount(); j++) { MgPropertyDefinition idProp = classDefProps.GetItem(j); idPropNames.Add(idProp.GetName()); } MgSelection sel = new MgSelection(map); do { // Generate XML to selection this feature MgPropertyCollection idProps = new MgPropertyCollection(); foreach (string id in idPropNames) { int idPropType = features.GetPropertyType(id); switch (idPropType) { case MgPropertyType.Int32: idProps.Add(new MgInt32Property(id, features.GetInt32(id))); break; case MgPropertyType.String: idProps.Add(new MgStringProperty(id, features.GetString(id))); break; case MgPropertyType.Int64: idProps.Add(new MgInt64Property(id, features.GetInt64(id))); break; case MgPropertyType.Double: idProps.Add(new MgDoubleProperty(id, features.GetDouble(id))); break; case MgPropertyType.Single: idProps.Add(new MgSingleProperty(id, features.GetSingle(id))); break; case MgPropertyType.DateTime: idProps.Add(new MgDateTimeProperty(id, features.GetDateTime(id))); break; default: //throw new SearchError(String.Format(MgLocalizer.GetString("SEARCHTYYPENOTSUP", locale), new Object[] { idPropType.ToString() }), searchError); break; } } sel.AddFeatureIds(layer, featureClassName, idProps); selAll.AddFeatureIds(layer, featureClassName, idProps); n++; //if (n > 1000) break; } while (features.ReadNext()); features.Close(); features.Dispose(); string selText = EscapeForHtml(sel.ToXml()); string seljs = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/></div>"; string seljs3 = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/></div>"; string linfo = "<b>" + layer.LegendLabel + "</b><br />" + n.ToString() + " " + "Hits"; sbOut.Append("<tr><td class=\"results\">" + nSloj.ToString() + "</td><td class=\"results\">" + linfo + "</td><td align=\"center\" class=\"results\">" + seljs + "</td><td align=\"center\" class=\"results\">" + seljs3 + "</td></tr>"); } } catch (Exception) { continue; } nextlay: continue; } sbOut.Append("</table>"); string selAllText = EscapeForHtml(selAll.ToXml()); string seljsAll = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/>" + "Select All" + "</div>"; string seljsAll3 = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/>" + "Report All" + "</div>"; sbOut.Append(string.Format("<br /><table width=\"100%\" class=\"results\"><tr><td class=\"results\">{0}</td><td class=\"results\">{1}</td></tr></table>", seljsAll, seljsAll3)); featureSrvc.Dispose(); resourceSrvc.Dispose(); if (nSloj > 0) { litPrebodi.Text = sbOut.ToString(); } else { litPrebodiTitle.Visible = false; litPrebodi.Text = "<b>" + "None layer lies below the selected item/area!" + "</b>"; } MgGeometry inGeom = wktrw.Read(GEOMETRY); double rw = map.ViewScale / Math.Sqrt(inGeom.Area); //koordinate if (hasInputGeom & rw > 400) { string output = ""; output = pointTransformAndWriteZ(GEOMETRY, map); litKoordinate.Text = output; litKoordinateTitle.Text = "Coordinates of selected points:"; } } }
public string QueryMapFeatures(RuntimeMap rtMap, int maxFeatures, string wkt, bool persist, string selectionVariant, QueryMapOptions extraOptions) { var impl = rtMap as LocalRuntimeMap; if (impl == null) throw new ArgumentException("Instance is not a LocalRuntimeMap", "map"); //LOCALIZEME var rs = GetRenderingService(); var res = GetResourceService(); var map = impl.GetWrappedInstance(); MgWktReaderWriter r = new MgWktReaderWriter(); MgStringCollection layerNames = null; string featureFilter = ""; int layerAttributeFilter = 0; int op = MgFeatureSpatialOperations.Intersects; if (selectionVariant == "TOUCHES") op = MgFeatureSpatialOperations.Touches; else if (selectionVariant == "INTERSECTS") op = MgFeatureSpatialOperations.Intersects; else if (selectionVariant == "WITHIN") op = MgFeatureSpatialOperations.Within; else if (selectionVariant == "ENVELOPEINTERSECTS") op = MgFeatureSpatialOperations.EnvelopeIntersects; else throw new ArgumentException("Unknown or unsupported selection variant: " + selectionVariant); if (extraOptions != null) { if (!string.IsNullOrEmpty(extraOptions.FeatureFilter)) featureFilter = extraOptions.FeatureFilter; if (extraOptions.LayerNames != null && extraOptions.LayerNames.Length > 0) { layerNames = new MgStringCollection(); foreach (var name in extraOptions.LayerNames) layerNames.Add(name); } layerAttributeFilter = (int)extraOptions.LayerAttributeFilter; } MgdFeatureInformation info = rs.QueryFeatures(map, layerNames, r.Read(wkt), op, featureFilter, maxFeatures, layerAttributeFilter); string xml = ""; GetByteReaderMethod fetch = () => { return info.ToXml(); }; using (var sr = new StreamReader(new MgReadOnlyStream(fetch))) { xml = sr.ReadToEnd(); } impl.Selection.LoadXml(xml); return xml; }