public ActionResult SelectFeature(SelectInputModel 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]; MgClassDefinition clsDef = layer.GetClassDefinition(); MgPropertyDefinitionCollection props = clsDef.GetProperties(); MgPropertyDefinition idProp = props[0]; string idPropName = idProp.Name; MgFeatureQueryOptions query = new MgFeatureQueryOptions(); query.SetFilter(idPropName + " = " + input.id); MgFeatureReader reader = layer.SelectFeatures(query); MgSelection selection = new MgSelection(map, ""); MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService); string result = ""; try { selection.Open(resSvc, input.MapName); selection.FromXml(""); //Clear existing selection.AddFeatures(layer, reader, 0); result = selection.ToXml(); } finally { reader.Close(); } return(Content(result, MgMimeType.Xml)); }
public IActionResult SelectFeature(SelectInputModel 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); MgClassDefinition clsDef = layer.GetClassDefinition(); MgPropertyDefinitionCollection props = clsDef.GetProperties(); MgPropertyDefinition idProp = props.GetItem(0); string idPropName = idProp.Name; MgFeatureQueryOptions query = new MgFeatureQueryOptions(); query.SetFilter(idPropName + " = " + input.id); MgFeatureReader reader = layer.SelectFeatures(query); MgSelection selection = new MgSelection(map, ""); MgResourceService resSvc = (MgResourceService)conn.CreateService(MgServiceType.ResourceService); string result = ""; try { selection.Open(resSvc, input.MapName); selection.FromXml(""); //Clear existing selection.AddFeatures(layer, reader, 0); result = selection.ToXml(); selection.Save(resSvc); } finally { reader.Close(); } return Content(result, MgMimeType.Xml); }
public String GetSelectionXML() { MgMap map = new MgMap(); map.Open(_resourceService, GetParameter(this.args, "MAPNAME")); MgLayerBase markupLayer = map.GetLayers().GetItem("_" + this.GetMarkupName()); MgSelection selection = new MgSelection(map); selection.AddFeatureIdInt32(markupLayer, markupLayer.FeatureClassName, Int32.Parse(GetParameter(this.args, "MARKUPFEATURE"))); return selection.ToXml(); }
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:"; } } }
//--------------------------------------------------------------------------------------- // // ���ܣ�����ѯ���ת��ΪXML��ʽ���ַ� // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public void CreateSelectionXML(String queryString) { //������Դ��Ҫ�ط��� MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); //��ȡҪ��ѯ��Ҫ��������ڵIJ� MgMap map = new MgMap(); map.Open(resService, "Sheboygan"); MgLayer layer = map.GetLayers().GetItem("Parcels"); //ִ��Ҫ�ز�ѯ MgResourceIdentifier resId = new MgResourceIdentifier(layer.GetFeatureSourceId()); MgFeatureQueryOptions queryOption = new MgFeatureQueryOptions(); queryOption.SetFilter(queryString); MgFeatureReader featureReader = featureService.SelectFeatures(resId, "Parcels", queryOption); //����ѡ�� MgSelection selection = new MgSelection(map); selection.AddFeatures(layer, featureReader, 0); //����ѡ����ת��ΪXML OutputSelectionInHTML(selection, featureService); selectionXML = selection.ToXml(); }
public string SelectFeaturesOnMap(string layerName, string[] ids) { string result = string.Empty; if (this.Map.GetLayers().Contains(layerName)) { MgLayer layer = this.Map.GetLayers().GetItem(layerName) as MgLayer; MgFeatureQueryOptions opt = new MgFeatureQueryOptions(); string identityName = this.FeatureService.GetClassDefinition(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName.Split(new char[] { ':' })[0], layer.FeatureClassName.Split(new char[] { ':'})[1]).GetIdentityProperties()[0].Name; opt.SetFilter(string.Format("{0} in({1})", identityName, ids.ToString())); MgFeatureReader reader = this.FeatureService.SelectFeatures(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName, opt); MgSelection selection = new MgSelection(this.Map); selection.AddFeatures(layer, reader, ids.Length); result = selection.ToXml(); } return result; }