public virtual MgSelection getSelection() { global::System.IntPtr cPtr = touchvgPINVOKE.MgCmdManager_getSelection(swigCPtr); MgSelection ret = (cPtr == global::System.IntPtr.Zero) ? null : new MgSelection(cPtr, false); return(ret); }
public void AddBuffer() { MgMap map = new MgMap(); map.Open(_resourceService, GetParameter(this.args, "MAPNAME")); MgSelection selection = new MgSelection(map); selection.Open(_resourceService, map.Name); MgReadOnlyLayerCollection layers = selection.GetLayers(); if (layers != null && layers.Count == 1) { MgFeatureQueryOptions opt = new MgFeatureQueryOptions(); opt.SetFilter(selection.GenerateFilter(layers[0], layers[0].FeatureClassName)); MgFeatureReader featureReader = _featureService.SelectFeatures(new MgResourceIdentifier(layers[0].FeatureSourceId), layers[0].FeatureClassName, opt); MgAgfReaderWriter agfRW = new MgAgfReaderWriter(); MgGeometryCollection inputGeometries = new MgGeometryCollection(); MgClassDefinition classDef = _featureService.GetClassDefinition( new MgResourceIdentifier(layers[0].FeatureSourceId), layers[0].FeatureClassName.Split(':')[0], layers[0].FeatureClassName.Split(':')[1]); while (featureReader.ReadNext()) { MgByteReader byteReader = featureReader.GetGeometry(classDef.DefaultGeometryPropertyName); MgGeometry geom = agfRW.Read(byteReader); inputGeometries.Add(geom); } if (inputGeometries.Count > 0) { MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory(); MgCoordinateSystem mapSrs = coordSysFactory.Create(map.MapSRS); double distance = mapSrs.ConvertMetersToCoordinateSystemUnits(7.0); MgCoordinateSystemMeasure measure = mapSrs.GetMeasure(); MgGeometryFactory geomFactory = new MgGeometryFactory(); MgGeometry buffer = geomFactory.CreateMultiGeometry(inputGeometries).Buffer(distance, measure); if (buffer != null) { MgByteReader byteReader = agfRW.Write(buffer); MgGeometryFactory geometryFactory = new MgGeometryFactory(); MgAgfReaderWriter agfWriter = new MgAgfReaderWriter(); MgPropertyCollection propertyValues = CreatePropertyCollection(byteReader); this.InsertMarkupFeature(propertyValues); } } } }
public static int GetUidFromSelection(HtzMgHelper helper, MgSelection selection, string idField) { MgLayer layer = selection.GetLayers()[0] as MgLayer; if (layer == null) { return 0; } MgFeatureQueryOptions opt = new MgFeatureQueryOptions(); opt.SetFilter(selection.GenerateFilter(layer, layer.FeatureClassName)); MgFeatureReader reader = helper.FeatureService.SelectFeatures(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName, opt); reader.ReadNext(); int result = (int)helper.GetFeaturePropertyValue(reader, idField); reader.Close(); reader.Dispose(); return result; }
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)); }
//--------------------------------------------------------------------------------------- // // ���ܣ������ѯ��� // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public void OutputSelectionInHTML(MgSelection selection, MgFeatureService featureService) { MgReadOnlyLayerCollection layers = selection.GetLayers(); String outString = null; if (layers != null) { for (int i = 0; i < layers.GetCount(); i++) { MgLayer layer = layers.GetItem(i); if ((layer != null) && (layer.GetName() == "Parcels")) { String layerClassName = layer.GetFeatureClassName(); selectString = selection.GenerateFilter(layer, layerClassName); String layerFeatureIdString = layer.GetFeatureSourceId(); MgResourceIdentifier layerResId = new MgResourceIdentifier(layerFeatureIdString); MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions(); queryOptions.SetFilter(selectString); MgFeatureReader featReader = featureService.SelectFeatures(layerResId, layerClassName, queryOptions); outString = outString + "<table border=\"1\">\n"; double acre = 0; while (featReader.ReadNext()) { outString = outString + "<tr>\n"; outString = outString + "<td>"; outString = outString + featReader.GetString("RNAME"); outString = outString + "</td>\n"; outString = outString + "<td>"; outString = outString + featReader.GetString("RPROPAD"); outString = outString + "</td>\n"; outString = outString + "<td>"; String acreString = featReader.GetString("RACRE"); acre = acre + (acreString == "" ? 0 : Convert.ToDouble(acreString)); outString = outString + acreString; outString = outString + "</tr>\n"; } outString = outString + "</table>\n"; featReader.Close(); } } } selectionResult = outString; }
//--------------------------------------------------------------------------------------- // // ���ܣ��г���ǰѡ���Ҫ������ // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public bool ListSelections() { MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgMap map = new MgMap(); map.Open(resService, "Sheboygan"); MgSelection mapSelection = new MgSelection(map); mapSelection.Open(resService, "Sheboygan"); if (mapSelection.GetLayers() != null) { OutputSelectionInHTML(mapSelection, featService); return true; } else { return false; } }
public ParcelProperty GetFirstSelectedFeature() { MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgMap map = new MgMap(); map.Open(resService, "Sheboygan"); MgSelection mapSelection = new MgSelection(map); mapSelection.Open(resService, "Sheboygan"); MgReadOnlyLayerCollection layers = mapSelection.GetLayers(); if (layers == null) return null; ParcelProperty prop = new ParcelProperty(); for (int i = 0; i < layers.GetCount(); i++) { MgLayer layer = layers.GetItem(i); if ((layer != null) && (layer.GetName() == "Parcels")) { String layerClassName = layer.GetFeatureClassName(); String selectString = mapSelection.GenerateFilter(layer, layerClassName); String layerFeatureIdString = layer.GetFeatureSourceId(); MgResourceIdentifier layerResId = new MgResourceIdentifier(layerFeatureIdString); MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions(); queryOptions.SetFilter(selectString); MgFeatureReader featReader = featService.SelectFeatures(layerResId, layerClassName, queryOptions); if (featReader.ReadNext()) { prop.ID = featReader.GetInt32("Autogenerated_SDF_ID"); prop.Acreage = featReader.GetString("RACRE"); prop.BillingAddr = featReader.GetString("RBILAD"); prop.Description1 = featReader.GetString("RLDESCR1"); prop.Description2 = featReader.GetString("RLDESCR2"); prop.Description3 = featReader.GetString("RLDESCR3"); prop.Description4 = featReader.GetString("RLDESCR4"); prop.LotDimension = featReader.GetString("RLOT"); prop.LotSize = featReader.GetInt32("RSQFT"); prop.Owner = featReader.GetString("RNAME"); prop.Zoning = featReader.GetString("RTYPE"); featReader.Close(); return prop; } featReader.Close(); } } return null; }
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:"; } } }
MgGeometry MultiGeometryFromSelection(MgFeatureService featureSrvc, MgMap map, String selText) { MgSelection sel = new MgSelection(map); sel.FromXml(selText); MgReadOnlyLayerCollection selLayers = sel.GetLayers(); if (selLayers == null) { return(null); } MgGeometryCollection geomColl = new MgGeometryCollection(); MgAgfReaderWriter agfRW = new MgAgfReaderWriter(); bool polyOnly = true; for (int i = 0; i < selLayers.GetCount(); i++) { MgLayer layer = (MgLayer)selLayers.GetItem(i); // TODO: How to get selectionSize? //int selectionSize = 20; string filter = sel.GenerateFilter(layer, layer.GetFeatureClassName()); if (filter == "") { continue; } MgFeatureQueryOptions query = new MgFeatureQueryOptions(); query.SetFilter(filter); MgResourceIdentifier featureSource = new MgResourceIdentifier(layer.GetFeatureSourceId()); MgFeatureReader features = featureSrvc.SelectFeatures(featureSource, layer.GetFeatureClassName(), query); if (features != null) { MgClassDefinition classDef = features.GetClassDefinition(); String geomPropName = classDef.GetDefaultGeometryPropertyName(); int j = 0; //bool isPoly = true; while (features.ReadNext()) { MgByteReader geomReader = features.GetGeometry(geomPropName); MgGeometry geom = agfRW.Read(geomReader); if (j++ == 0) { int type = geom.GetGeometryType(); if (type == MgGeometryType.MultiPolygon || type == MgGeometryType.CurvePolygon || type == MgGeometryType.MultiCurvePolygon) { //isPoly = false; polyOnly = false; } else if (type != MgGeometryType.Polygon) { break; } } geomColl.Add(geom); } features.Close(); features.Dispose(); } } if (geomColl.GetCount() == 0) { return(null); } MgGeometryFactory gf = new MgGeometryFactory(); if (polyOnly) { MgPolygonCollection polyColl = new MgPolygonCollection(); for (int j = 0; j < geomColl.GetCount(); j++) { polyColl.Add((MgPolygon)geomColl.GetItem(j)); } return(gf.CreateMultiPolygon(polyColl)); } else { return(gf.CreateMultiGeometry(geomColl)); } }
public override System.IO.Stream RenderRuntimeMap(RuntimeMap rtmap, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format, bool clip) { var resourceId = rtmap.ResourceID; MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgGeometryFactory gf = new MgGeometryFactory(); string mapname = new ResourceIdentifier(resourceId).Path; //TODO: The render is missing the clip param for the extent override method GetByteReaderMethod fetch = () => { MgMap map = new MgMap(); map.Open(res, mapname); MgSelection sel = new MgSelection(map); //The color accepted by MgColor has alpha as the last value, but the returned has alpha first MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor())); MgEnvelope env = new MgEnvelope(gf.CreateCoordinateXY(x1, y1), gf.CreateCoordinateXY(x2, y2)); return rnd.RenderMap(map, sel, env, width, height, color, format); }; LogMethodCall("MgRenderingService::RenderMap", true, "MgMap", "MgSelection", "MgEnvelope", width.ToString(), height.ToString(), "MgColor", format); return new MgReadOnlyStream(fetch); }
public Dictionary<string, string> GetSelectedLayers(MgSelection selection, bool addGroupName) { Dictionary<string, string> result = new Dictionary<string, string>(); foreach (MgLayerBase l in selection.GetLayers()) { string label = l.LegendLabel; if (addGroupName) { for (MgLayerGroup group = l.Group; group != null; group = group.Group) { label = string.Format("{0} - {1}", group.LegendLabel, label); } } result.Add(l.Name, label); } return result; }
public override Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format, Color selectionColor, int behaviour) { MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgMap mmap = new MgMap(); mmap.Open(res, map.Name); MgSelection sel = new MgSelection(mmap); if (selection != null) sel.FromXml(selection.ToXml()); var rndOpts = new MgRenderingOptions(format, behaviour, new MgColor(selectionColor)); GetByteReaderMethod fetch = () => { return rnd.RenderDynamicOverlay(mmap, sel, rndOpts); }; LogMethodCall("MgRenderingService::RenderDynamicOverlay", true, "MgMap", "MgSelection", "MgRenderingOptions"); return new MgReadOnlyStream(fetch); }
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 getPlanMapImageAsBase64String(string planID, string imageWidth, string imageHeight) { try { MgUserInformation userInfo = null; string mapWebTierInit = ConfigurationManager.AppSettings["MGWebTierInit"].ToString(); MapGuideApi.MgInitializeWebTier(mapWebTierInit); // Om kartsession finns för applikationssession använd den annars skapa ny kartssitesession string mapSiteSessionID = null; if (Session["MapSiteSessionID"] != null) { mapSiteSessionID = Session["MapSiteSessionID"].ToString(); userInfo = new MgUserInformation(mapSiteSessionID); } else { // Initierar kartsite och kartsession string mapUserName = ConfigurationManager.AppSettings["MGUserName"].ToString(); string mapUserPass = ConfigurationManager.AppSettings["MGUserPass"].ToString(); userInfo = new MgUserInformation(mapUserName, mapUserPass); MgSite mapSite = new MgSite(); mapSite.Open(userInfo); userInfo.Dispose(); mapSiteSessionID = mapSite.CreateSession(); //mapSite.Close(); Session["MapSiteSessionID"] = mapSiteSessionID; userInfo = new MgUserInformation(mapSiteSessionID); } //bool test = resSvc.ResourceExists(mapResId); string mapSurfaceFactor = ConfigurationManager.AppSettings["MGMapSurfaceFactor"].ToString(); string mapRes = ConfigurationManager.AppSettings["MGMapResource"].ToString(); string planRes = ConfigurationManager.AppSettings["MGPlanytorResource"].ToString(); string planClassName = ConfigurationManager.AppSettings["MGPlanytorClassName"].ToString(); string planFilterColumn = ConfigurationManager.AppSettings["MGPlanytorFilterColumn"].ToString(); string planGeometryColumn = ConfigurationManager.AppSettings["MGPlanytorGeometryColumn"].ToString(); string planytorStrokeRgbaColor = ConfigurationManager.AppSettings["MGPlanytorStrokeRgbaColor"].ToString(); string planytorForegroundRgbaColor = ConfigurationManager.AppSettings["MGPlanytorForegroundRgbaColor"].ToString(); string mapImageSizeFromServer = ConfigurationManager.AppSettings["MGMapImageSizeFromServer"].ToString(); // Standardvärde för storlek på kartbild, används om värde ej finns i Settings.config eller skickas in som parametrar i webbmetod string mapImageWidthPixel = "400"; string mapImageHeightPixel = "300"; // Väljer bredd och höjd på kartbild om värde ska finnas i Settings.config samt indikeras att de ska användas // annars förväntas värde skickas med i webbmetod if (mapImageSizeFromServer.ToLower() == "true") { mapImageWidthPixel = ConfigurationManager.AppSettings["MGMapImageWidth"].ToString(); mapImageHeightPixel = ConfigurationManager.AppSettings["MGMapImageHeight"].ToString(); } else { if (!string.IsNullOrWhiteSpace(imageWidth) && !string.IsNullOrWhiteSpace(imageHeight)) { mapImageWidthPixel = imageWidth; mapImageHeightPixel = imageHeight; } } MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); MgResourceService resSvc = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgResourceIdentifier mapResId = new MgResourceIdentifier(mapRes); MgFeatureService featSvc = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgResourceIdentifier planResId = new MgResourceIdentifier(planRes); // Filter för planDoc efter planDoc-ID MgFeatureQueryOptions featureQuery = new MgFeatureQueryOptions(); featureQuery.SetFilter(planFilterColumn + " = " + planID); MgFeatureReader featureReader = featSvc.SelectFeatures(planResId, planClassName, featureQuery); MgByteReader byteReaderGeometry = null; MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgGeometryCollection geometryCollection = new MgGeometryCollection(); int featureCount = 0; try { while (featureReader.ReadNext()) { byteReaderGeometry = featureReader.GetGeometry(planGeometryColumn); MgGeometry districtGeometry = agfReaderWriter.Read(byteReaderGeometry); geometryCollection.Add(districtGeometry); featureCount++; } } finally { featureReader.Close(); } MgGeometryFactory geometryFactory = new MgGeometryFactory(); MgMultiGeometry multiGeometry = geometryFactory.CreateMultiGeometry(geometryCollection); MgMap map = new MgMap(siteConnection); MgEnvelope envelope = multiGeometry.Envelope(); // Anpassar ev. punkt till komma i tal som hanteras som textsträng för kommande konvertering if (mapImageHeightPixel.IndexOf(".") != -1) { mapImageHeightPixel = mapImageHeightPixel.Replace(".", ","); } if (mapImageWidthPixel.IndexOf(".") != -1) { mapImageWidthPixel = mapImageWidthPixel.Replace(".", ","); } // Önskad bilds höjd och bredd i punkter double imageHeightPixel = Convert.ToDouble(mapImageHeightPixel); double imageWidthPixel = Convert.ToDouble(mapImageWidthPixel); map.DisplayDpi = 120; double heightEnvelopeN = envelope.Height; double widthEnvelopeE = envelope.Width; // Anpassar utbredningen på sökta planer (envelope) till bildens format för att bevara skalriktighet string mapFarthest = string.Empty; if (heightEnvelopeN > widthEnvelopeE) mapFarthest = "height"; else mapFarthest = "width"; string imageFarthest = string.Empty; if (imageHeightPixel > imageWidthPixel) imageFarthest = "height"; else imageFarthest = "width"; double scale = 1.0; const double inch = 2.54; // Ändring av kartans utbredning och addering av utrymme i kartans bild runt planavgränsningen // Map = avgränsning enligt planytan (utbredning i kartan), Image = önskad bild att skapa med kartan // Om: kartans höjd är längst & bildens bredd är längst if (mapFarthest == "height" && imageFarthest == "width") { scale = imageWidthPixel / imageHeightPixel * inch; widthEnvelopeE = imageWidthPixel / imageHeightPixel * heightEnvelopeN * scale; } // Om: kartans bredd är längst & bildens höjd är längst else if (mapFarthest == "width" && imageFarthest == "height") { scale = imageHeightPixel / imageWidthPixel * inch; heightEnvelopeN = imageHeightPixel / imageWidthPixel * widthEnvelopeE * scale; } // Om: kartans höjd är längst & bildens höjd är längst else if (mapFarthest == "height" && imageFarthest == "height") { double compareSide = (heightEnvelopeN / (imageHeightPixel / imageWidthPixel)); bool isCompareSideFarthest = false; if (compareSide > widthEnvelopeE) { isCompareSideFarthest = true; } else { isCompareSideFarthest = false; } scale = imageHeightPixel / imageWidthPixel * inch; if (isCompareSideFarthest) { widthEnvelopeE = heightEnvelopeN / (imageHeightPixel / imageWidthPixel) * scale; } else { heightEnvelopeN = (imageHeightPixel / imageWidthPixel) * widthEnvelopeE * scale; } } // Om(annars): kartans bredd är längst & bildens bredd är längst else { double compareSide = (widthEnvelopeE / (imageWidthPixel / imageHeightPixel)); bool isCompareSideFarthest = false; if (compareSide > heightEnvelopeN) { isCompareSideFarthest = true; } else { isCompareSideFarthest = false; } scale = imageWidthPixel / imageHeightPixel * inch; if (isCompareSideFarthest) { heightEnvelopeN = widthEnvelopeE / (imageWidthPixel / imageHeightPixel) * scale; } else { widthEnvelopeE = heightEnvelopeN * (imageWidthPixel / imageHeightPixel) * scale; } } double mapSurfaceFactorDbl = Convert.ToDouble(mapSurfaceFactor.Replace('.', ',')); double newHeightN = heightEnvelopeN * mapSurfaceFactorDbl; double newWidthE = widthEnvelopeE * mapSurfaceFactorDbl; MgCoordinate lowerLeft = envelope.LowerLeftCoordinate; MgCoordinate upperRight = envelope.UpperRightCoordinate; envelope = new MgEnvelope(lowerLeft.X - (newWidthE - widthEnvelopeE) / 2, lowerLeft.Y - (newHeightN - heightEnvelopeN) / 2, upperRight.X + (newWidthE - widthEnvelopeE) / 2, upperRight.Y + (newHeightN - heightEnvelopeN) / 2); map.Create(resSvc, mapResId, mapResId.Name); // Skapa lagerdefinition i XML DefineAreaLayer areaLayer = new DefineAreaLayer(); areaLayer.FeatureName = planClassName; areaLayer.FeatureSourceName = planRes; areaLayer.GeometryColumnName = planGeometryColumn; areaLayer.Filter = planFilterColumn + " = " + planID; LayerScaleRangeCollection lsrCollection = new LayerScaleRangeCollection(); LayerScaleRange lsr = new LayerScaleRange(); // MinScale applikations-default till 0 (inklusive) om utelämnat, MaxScale applikations-default till kartans maxskala (exklusive) om utelämnat //lsr.MinScale = "0"; //lsr.MaxScale = "100000000"; AreaTypeStyle ats = new AreaTypeStyle(); AreaRuleCollection arCollection = new AreaRuleCollection(); AreaRule ar = new AreaRule(); //ar.Filter = planFilterColumn + " = " + planID; ar.LegendLabel = "Plan" + planID; AreaSymbolization2D symb2D = new AreaSymbolization2D(); Fill fill = new Fill(); fill.BackgroundColor = "FFFF0000"; fill.FillPattern = "Solid"; fill.ForegroundColor = convertRgbsToHexColor(planytorForegroundRgbaColor); Stroke stroke = new Stroke(); stroke.Color = convertRgbsToHexColor(planytorStrokeRgbaColor); stroke.LineStyle = "Solid"; stroke.Thickness = "1"; stroke.Unit = "Points"; symb2D.Fill = fill; symb2D.Stroke = stroke; ar.Symbolization2D = symb2D; arCollection.Add(ar); ats.AreaRules = arCollection; lsr.AreaTypeStyle = ats; lsrCollection.Add(lsr); areaLayer.LayerScaleRanges = lsrCollection; XmlDocument xmlFile = new XmlDocument(); //XDocument xmlFile = new XDocument(); // om returnerande av xml-dokument //xmlFile = areaLayer.CreateLayerDefinitionAsXmlDocument(); // om returnerande av xml-sträng xmlFile.LoadXml(areaLayer.CreateLayerDefinitionAsXmlString()); //xmlFile = areaLayer.CreateLayerDefinitionAsXDocument(); //xmlFile.Save(Server.MapPath(this.Context.Request.ApplicationPath) + "XmlTestLayerDefinition.xml"); using (MemoryStream msNewPlanLayer = new MemoryStream()) { xmlFile.Save(msNewPlanLayer); msNewPlanLayer.Position = 0L; //Note we do this to ensure our XML content is free of any BOM characters byte[] layerDefinition = msNewPlanLayer.ToArray(); Encoding utf8 = Encoding.UTF8; String layerDefStr = new String(utf8.GetChars(layerDefinition)); layerDefinition = new byte[layerDefStr.Length - 1]; int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0); // Save the new layer definition to the session repository MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.Length); MgResourceIdentifier layerResourceID = new MgResourceIdentifier("Session:" + mapSiteSessionID + "//" + "planytor" + ".LayerDefinition"); //"SearchedPlan" + planID + ".LayerDefinition"); resSvc.SetResource(layerResourceID, byteSource.GetReader(), null); MgLayer newPlanLayer = new MgLayer(layerResourceID, resSvc); newPlanLayer.SetName("Sökta planer"); newPlanLayer.SetVisible(true); newPlanLayer.SetLegendLabel("Sökta planer"); newPlanLayer.SetDisplayInLegend(true); MgLayerCollection layerCollection = map.GetLayers(); if (!layerCollection.Contains(newPlanLayer)) { // Insert the new layer at position 0 so it is at the top // of the drawing order layerCollection.Insert(0, newPlanLayer); } else { layerCollection.Remove(newPlanLayer); layerCollection.Insert(0, newPlanLayer); } map.Save(); } double mapScale = map.ViewScale; // XML-dokument till ren text //StringWriter stringWriter = new StringWriter(); //XmlWriter xmlTextWriter = XmlWriter.Create(stringWriter); //xmlFile.WriteTo(xmlTextWriter); //xmlTextWriter.Flush(); string xmlSelection = string.Empty; //string xmlSelection = stringWriter.GetStringBuilder().ToString(); MgSelection selection = null; if (!string.IsNullOrEmpty(xmlSelection)) { selection = new MgSelection(map, xmlSelection); } else { selection = new MgSelection(map); } MgColor color = new MgColor("255,255,255"); // Skapar bild av kartan MgRenderingService renderingService = (MgRenderingService)siteConnection.CreateService(MgServiceType.RenderingService); //MgByteReader byteReader = renderingService.RenderMap(map, selection, "PNG"); MgByteReader byteReader = renderingService.RenderMap(map, selection, envelope, Convert.ToInt32(imageWidthPixel), Convert.ToInt32(imageHeightPixel), color, "PNG"); MemoryStream ms = new MemoryStream(); byte[] byteBuffer = new byte[1024]; int numBytes = byteReader.Read(byteBuffer, 1024); while (numBytes > 0) { ms.Write(byteBuffer, 0, numBytes); numBytes = byteReader.Read(byteBuffer, 1024); } byte[] mapImageByte = ms.ToArray(); string imageBase64String = Convert.ToBase64String(mapImageByte); map.Dispose(); siteConnection.Dispose(); DataTable dtResult = new DataTable(); DataColumn dc = new DataColumn("MAPIMAGEBASE64"); dtResult.Columns.Add(dc); dc = new DataColumn("WIDTH"); dtResult.Columns.Add(dc); dc = new DataColumn("HEIGHT"); dtResult.Columns.Add(dc); DataRow dr = dtResult.NewRow(); dr["MAPIMAGEBASE64"] = imageBase64String; dr["WIDTH"] = imageWidthPixel; dr["HEIGHT"] = imageHeightPixel; dtResult.Rows.Add(dr); //TODO: MAP: Vad kan returneras, base64 eller länk där bild temporärt genereras på server //JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); //return jsonSerializer.Serialize(imageBase64String); return getDatatableAsJson(dtResult); } catch (System.Exception ex) { UtilityException.LogException(ex, "Webbmetod : getPlanMapImageAsBase64String", true); return null; } }
//--------------------------------------------------------------------------------------- // // ���ܣ�����ѯ���ת��Ϊ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(); }
//--------------------------------------------------------------------------------------- // // ���ܣ��г���ǰѡ���Ҫ������ // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public int ListSelections() { // ������Դ�����Ҫ�ط��� MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); //��ͼ������ѡ���� MgMap map = new MgMap(); map.Open(resService, "Sheboygan"); MgSelection mapSelection = null; mapSelection = new MgSelection(map); mapSelection.Open(resService, "Sheboygan"); // ����ѡ�� if (mapSelection.GetLayers() != null) { OutputSelectionInHTML(mapSelection, featService); return 1; } else { return 0; } }
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; }
public Dictionary<string, string> GetSelectedLayers(string selectionXml, bool addGroupName) { MgSelection sel = new MgSelection(this.Map, selectionXml); return this.GetSelectedLayers(sel, addGroupName); }
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(); }
public static List<Feature> GetFeatures(HtzMgHelper helper, MgSelection selection, string layerName) { MgFeatureReader reader; List<Feature> result = new List<Feature>(); MgLayer layer = (MgLayer)helper.Map.GetLayers().GetItem(layerName); if ((selection != null) && (selection.GetLayers() != null)) { string filter = selection.GenerateFilter(layer, layer.FeatureClassName); MgFeatureQueryOptions opt = new MgFeatureQueryOptions(); opt.SetFilter(filter); reader = helper.FeatureService.SelectFeatures(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName, opt); } else { reader = helper.FeatureService.SelectFeatures(new MgResourceIdentifier(layer.FeatureSourceId), layer.FeatureClassName, null); } if (reader.ReadNext()) { Feature prototype = new Feature(helper, layerName, ""); Feature f1 = prototype.Clone() as Feature; f1.FillValues(reader); result.Add(f1); while (reader.ReadNext()) { Feature f = prototype.Clone() as Feature; f.FillValues(reader); result.Add(f); } } return result; }
public Stream RenderMapLegend(RuntimeMap map, int width, int height, System.Drawing.Color backgroundColor, string format) { MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; GetByteReaderMethod fetch = () => { MgMap mmap = new MgMap(); mmap.Open(res, map.Name); MgSelection sel = new MgSelection(mmap); MgColor color = new MgColor(backgroundColor); return rnd.RenderMapLegend(mmap, width, height, color, format); }; LogMethodCall("MgRenderingService::RenderMapLegend", true, "MgMap", width.ToString(CultureInfo.InvariantCulture), height.ToString(CultureInfo.InvariantCulture), "#" + ColorTranslator.ToHtml(backgroundColor), format); return new MgReadOnlyStream(fetch); }
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 Feature GetSingleFeature(HtzMgHelper helper, MgSelection selection, string layerName) { return GetSingleFeature(helper, selection, layerName, "UID"); }
public override Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format, bool keepSelection) { MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; GetByteReaderMethod fetch = () => { MgMap mmap = new MgMap(); mmap.Open(res, map.Name); MgSelection sel = new MgSelection(mmap); if (selection != null) sel.FromXml(selection.ToXml()); return rnd.RenderDynamicOverlay(mmap, sel, format, keepSelection); }; LogMethodCall("MgRenderingService::RenderDynamicOverlay", true, "MgMap", "MgSelection", format, keepSelection.ToString()); return new MgReadOnlyStream(fetch); }
public static Feature GetSingleFeature(HtzMgHelper helper, MgSelection selection, string layerName, string uidKey) { Feature result = null; MgLayer layer = helper.Map.GetLayers().GetItem(layerName) as MgLayer; if ((selection != null) && (selection.GetLayers() != null)) { string filter = selection.GenerateFilter(layer, layer.FeatureClassName); result = GetSingleFeature(helper, filter, layerName, uidKey); } return result; }
public override System.IO.Stream RenderRuntimeMap(RuntimeMap rtmap, double x, double y, double scale, int width, int height, int dpi, string format, bool clip) { var resourceId = rtmap.ResourceID; MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgGeometryFactory gf = new MgGeometryFactory(); string mapname = new ResourceIdentifier(resourceId).Path; GetByteReaderMethod fetch = () => { MgMap map = new MgMap(); map.Open(res, mapname); MgSelection sel = new MgSelection(map); //The color accepted by MgColor has alpha as the last value, but the returned has alpha first MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor())); MgCoordinate coord = gf.CreateCoordinateXY(x, y); return rnd.RenderMap(map, sel, coord, scale, width, height, color, format, true); }; LogMethodCall("MgRenderingService::RenderMap", true, "MgMap", "MgSelection", "MgPoint("+ x + "," + y + ")", scale.ToString(), width.ToString(), height.ToString(), "MgColor", format, true.ToString()); return new MgReadOnlyStream(fetch); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MgSelection obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
MgGeometry MultiGeometryFromSelection(MgFeatureService featureSrvc, MgMap map, String selText) { MgSelection sel = new MgSelection(map); sel.FromXml(selText); MgReadOnlyLayerCollection selLayers = sel.GetLayers(); if (selLayers == null) return null; MgGeometryCollection geomColl = new MgGeometryCollection(); MgAgfReaderWriter agfRW = new MgAgfReaderWriter(); bool polyOnly = true; for (int i = 0; i < selLayers.GetCount(); i++) { MgLayer layer = (MgLayer)selLayers.GetItem(i); // TODO: How to get selectionSize? //int selectionSize = 20; string filter = sel.GenerateFilter(layer, layer.GetFeatureClassName()); if (filter == "") continue; MgFeatureQueryOptions query = new MgFeatureQueryOptions(); query.SetFilter(filter); MgResourceIdentifier featureSource = new MgResourceIdentifier(layer.GetFeatureSourceId()); MgFeatureReader features = featureSrvc.SelectFeatures(featureSource, layer.GetFeatureClassName(), query); if (features != null) { MgClassDefinition classDef = features.GetClassDefinition(); String geomPropName = classDef.GetDefaultGeometryPropertyName(); int j = 0; //bool isPoly = true; while (features.ReadNext()) { MgByteReader geomReader = features.GetGeometry(geomPropName); MgGeometry geom = agfRW.Read(geomReader); if (j++ == 0) { int type = geom.GetGeometryType(); if (type == MgGeometryType.MultiPolygon || type == MgGeometryType.CurvePolygon || type == MgGeometryType.MultiCurvePolygon) { //isPoly = false; polyOnly = false; } else if (type != MgGeometryType.Polygon) { break; } } geomColl.Add(geom); } features.Close(); features.Dispose(); } } if (geomColl.GetCount() == 0) { return null; } MgGeometryFactory gf = new MgGeometryFactory(); if (polyOnly) { MgPolygonCollection polyColl = new MgPolygonCollection(); for (int j = 0; j < geomColl.GetCount(); j++) { polyColl.Add((MgPolygon)geomColl.GetItem(j)); } return gf.CreateMultiPolygon(polyColl); } else { return gf.CreateMultiGeometry(geomColl); } }
//---------------------------------------------------------------------------------------- // �� �ܣ� ����ͼ���Ϊͼ���ļ� // // �� �ߣ� // // // �� �ڣ�2007.05.# // //----------------------------------------------------------------------------------------- public bool GenerateMapImage() { // ��ȡ��Դ�������Ⱦ������� MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgRenderingService renderingService = (MgRenderingService)siteConnection.CreateService(MgServiceType.RenderingService); // ��ͼ MgMap map = new MgMap(); map.Open(resourceService, "Sheboygan"); // ����ѡ�� MgSelection selection = new MgSelection(map); selection.Open(resourceService, "Sheboygan"); // ָ����Χ MgEnvelope extent = map.GetMapExtent(); double x = 0.5*extent.GetLowerLeftCoordinate().GetX(); double y = 0.5*extent.GetLowerLeftCoordinate().GetY() ; MgColor color = new MgColor("FFFFBF20"); // ���ɲ�����ͼ���ļ� MgByteReader byteReader = renderingService.RenderMap(map, selection, extent, 450, 613, color, "PNG"); MgByteSink byteSink = new MgByteSink(byteReader); string filePath = "C:\\Temp\\Map.PNG"; byteSink.ToFile(filePath); return true; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MgSelection obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }