public MgBufferControlImpl(IMapViewer viewer, string defaultLayerName, MeasurementUnit units) { InitializeComponent(); this.Title = Strings.TitleBuffer; _viewer = viewer; _sessionId = Guid.NewGuid().ToString(); var provider = viewer.GetProvider(); _resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); _featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService); cmbUnits.DataSource = Enum.GetValues(typeof(MeasurementUnit)); cmbUnits.SelectedItem = units; cmbBorderPattern.DataSource = Enum.GetValues(typeof(StockPattern)); cmbFillPattern.DataSource = Enum.GetValues(typeof(StockPattern)); cmbBorderPattern.SelectedItem = StockPattern.Solid; cmbFillPattern.SelectedItem = StockPattern.Solid; pnlFillColor.BackColor = Color.Red; pnlBorderColor.BackColor = Color.Black; numBufferDistance.Value = 1; numFillTransparency.Value = 50; numLineThickness.Value = 1; txtBufferLayer.Text = defaultLayerName; _viewer.SelectionChanged += new EventHandler(OnViewerSelectedChanged); OnViewerSelectedChanged(this, EventArgs.Empty); }
public void CreateBufferFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier bufferFeatureResId) { MgClassDefinition bufferClass = new MgClassDefinition(); bufferClass.SetName("BufferClass"); MgPropertyDefinitionCollection properties = bufferClass.GetProperties(); MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID"); idProperty.SetDataType(MgPropertyType.Int32); idProperty.SetReadOnly(true); idProperty.SetNullable(false); idProperty.SetAutoGeneration(true); properties.Add(idProperty); MgGeometricPropertyDefinition polygonProperty = new MgGeometricPropertyDefinition("BufferGeometry"); polygonProperty.SetGeometryTypes(MgFeatureGeometricType.Surface); polygonProperty.SetHasElevation(false); polygonProperty.SetHasMeasure(false); polygonProperty.SetReadOnly(false); polygonProperty.SetSpatialContextAssociation("defaultSrs"); properties.Add(polygonProperty); MgPropertyDefinitionCollection idProperties = bufferClass.GetIdentityProperties(); idProperties.Add(idProperty); bufferClass.SetDefaultGeometryPropertyName("BufferGeometry"); MgFeatureSchema bufferSchema = new MgFeatureSchema("BufferLayerSchema", "temporary schema to hold a buffer"); bufferSchema.GetClasses().Add(bufferClass); MgCreateSdfParams sdfParams = new MgCreateSdfParams("defaultSrs", wkt, bufferSchema); featureService.CreateFeatureSource(bufferFeatureResId, sdfParams); }
public static void ClearDataSource(MgFeatureService featSvc, MgResourceIdentifier fsId, String featureName) { MgDeleteFeatures deleteCmd = new MgDeleteFeatures(featureName, "ID >= 0"); //NOXLATE MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); commands.Add(deleteCmd); featSvc.UpdateFeatures(fsId, commands, false); }
public static void AddPointFeature(string FeatureName, MgPropertyCollection featureProps, MgPoint geom, MgFeatureService featureSrvc, MgResourceIdentifier dataSourceId) { MgByteReader geomReader = new MgAgfReaderWriter().Write(geom); MgGeometryProperty geometryProp = new MgGeometryProperty("GEOM", geomReader); featureProps.Add(geometryProp); MgInsertFeatures cmd = new MgInsertFeatures(FeatureName, featureProps); MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); commands.Add(cmd); ReleaseReader(featureSrvc.UpdateFeatures(dataSourceId, commands, false)); }
public RedlineEditor(IMapViewer viewer, RedlineLayer layer) { _viewer = viewer; _layer = layer; var provider = viewer.GetProvider(); _featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService); _wktRW = new MgWktReaderWriter(); _agfRW = new MgAgfReaderWriter(); _geomFact = new MgGeometryFactory(); }
public RedlineManager(IMapViewer viewer) { _map = viewer.GetMap(); _viewer = viewer; var provider = _viewer.GetProvider(); _resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); _featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService); _registry = new RedlineRegistry(SessionID, _resSvc, _featSvc); }
private MgFeatureService GetMgFeatureService(string sessionId) { MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"] + "../webconfig.ini"); MgUserInformation userInfo = new MgUserInformation(sessionId); MgSiteConnection site = new MgSiteConnection(); site.Open(userInfo); MgFeatureService resourceService = (MgFeatureService)site.CreateService(MgServiceType.FeatureService); return(resourceService); }
private void button2_Click(object sender, EventArgs e) { try { MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgByteReader response = featSvc.GetCapabilities(textBox1.Text, txtConnectionString.Text); new XmlResponseDialog(response).ShowDialog(); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgByteReader response = featSvc.GetFeatureProviders(); new XmlResponseDialog(response).ShowDialog(); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
private void button2_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); bool res = featSvc.TestConnection(txtFdoProvider.Text, txtConnectionString.Text); MessageBox.Show("Result: " + res); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
// Create a temporary Feature Source to store geocode results. public void CreateLocationMarkerFeatureSource(MgFeatureService featureService, MgResourceIdentifier locationMarkerDataResId, MgMap map) { //String ll84Wkt = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.25722293287],TOWGS84[0,0,0,0,0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degrees\",1]]"; //string ll84Wkt = "LOCAL_CS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]] "; MgCoordinateSystemFactory sysCoordsFactory = new MgCoordinateSystemFactory(); string srsDefMap = map.GetMapSRS(); string mapSrsUnits = string.Empty; srsDefMap = !string.IsNullOrEmpty(srsDefMap) ? srsDefMap : "LOCAL_CS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]] "; MgCoordinateSystem srsMap = sysCoordsFactory.Create(srsDefMap); MgClassDefinition locationClass = new MgClassDefinition(); locationClass.SetName("LocationMarker"); MgPropertyDefinitionCollection properties = locationClass.GetProperties(); MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID"); idProperty.SetDataType(MgPropertyType.Int32); idProperty.SetReadOnly(true); idProperty.SetNullable(false); idProperty.SetAutoGeneration(true); properties.Add(idProperty); MgDataPropertyDefinition addressProperty = new MgDataPropertyDefinition("Address"); addressProperty.SetDataType(MgPropertyType.String); addressProperty.SetLength(512); properties.Add(addressProperty); MgGeometricPropertyDefinition locationProperty = new MgGeometricPropertyDefinition("Location"); locationProperty.SetGeometryTypes(MgGeometryType.Point); locationProperty.SetHasElevation(false); locationProperty.SetHasMeasure(false); locationProperty.SetReadOnly(false); locationProperty.SetSpatialContextAssociation(srsMap.GetCsCode()); properties.Add(locationProperty); MgPropertyDefinitionCollection idProperties = locationClass.GetIdentityProperties(); idProperties.Add(idProperty); locationClass.SetDefaultGeometryPropertyName("Location"); MgFeatureSchema locationSchema = new MgFeatureSchema(); locationSchema.SetName("LocationMarkerSchema"); locationSchema.GetClasses().Add(locationClass); MgCreateSdfParams sdfParams = new MgCreateSdfParams(srsMap.GetCsCode(), srsDefMap, locationSchema); featureService.CreateFeatureSource(locationMarkerDataResId, sdfParams); }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgResourceIdentifier fsId = new MgResourceIdentifier(textBox1.Text); MgSpatialContextReader response = featSvc.GetSpatialContexts(fsId, checkBox1.Checked); new SpatialContextResultDialog(response).ShowDialog(); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgResourceIdentifier fsId = new MgResourceIdentifier(textBox1.Text); string sql = textBox2.Text; MgSqlDataReader reader = featSvc.ExecuteSqlQuery(fsId, sql); new ReaderResponseDialog(reader).ShowDialog(); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgResourceIdentifier resId = new MgResourceIdentifier(textBox1.Text); string sql = textBox2.Text; int res = featSvc.ExecuteSqlNonQuery(resId, sql); MessageBox.Show(res + " results affected"); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgFeatureAggregateOptions query = new MgFeatureAggregateOptions(); string[] propNames = txtProps.Text.Split(','); foreach (var p in propNames) { if (string.IsNullOrEmpty(p)) { continue; } query.AddFeatureProperty(p); } foreach (Pair p in lstComputed.Items) { query.AddComputedProperty(p.Name, p.Expr); } if (!string.IsNullOrEmpty(txtFilter.Text.Trim())) { query.SetFilter(txtFilter.Text.Trim()); } query.SelectDistinct(chkDistinct.Checked); MgResourceIdentifier fsId = new MgResourceIdentifier(txtFeatureSource.Text); MgDataReader reader = featSvc.SelectAggregate(fsId, txtClass.Text, query); new ReaderResponseDialog(reader).ShowDialog(); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
public void CreateBufferFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier bufferFeatureResId) { MgClassDefinition bufferClass = new MgClassDefinition(); bufferClass.SetName("BufferClass"); MgPropertyDefinitionCollection properties = bufferClass.GetProperties(); MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID"); idProperty.SetDataType(MgPropertyType.Int32); idProperty.SetReadOnly(true); idProperty.SetNullable(false); idProperty.SetAutoGeneration(true); properties.Add(idProperty); MgGeometricPropertyDefinition polygonProperty = new MgGeometricPropertyDefinition("BufferGeometry"); polygonProperty.SetGeometryTypes(MgFeatureGeometricType.Surface); polygonProperty.SetHasElevation(false); polygonProperty.SetHasMeasure(false); polygonProperty.SetReadOnly(false); polygonProperty.SetSpatialContextAssociation("defaultSrs"); properties.Add(polygonProperty); MgPropertyDefinitionCollection idProperties = bufferClass.GetIdentityProperties(); idProperties.Add(idProperty); bufferClass.SetDefaultGeometryPropertyName("BufferGeometry"); MgFeatureSchema bufferSchema = new MgFeatureSchema("BufferLayerSchema", "temporary schema to hold a buffer"); bufferSchema.GetClasses().Add(bufferClass); MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "defaultSrs", wkt, bufferSchema); featureService.CreateFeatureSource(bufferFeatureResId, sdfParams); }
public void CreateParcelMarkerFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier parcelMarkerDataResId) { MgClassDefinition parcelClass = new MgClassDefinition(); parcelClass.SetName("ParcelMarkerClass"); MgPropertyDefinitionCollection properties = parcelClass.GetProperties(); MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID"); idProperty.SetDataType(MgPropertyType.Int32); idProperty.SetReadOnly(true); idProperty.SetNullable(false); idProperty.SetAutoGeneration(true); properties.Add(idProperty); MgGeometricPropertyDefinition pointProperty = new MgGeometricPropertyDefinition("ParcelLocation"); pointProperty.SetGeometryTypes(MgGeometryType.Point); pointProperty.SetHasElevation(false); pointProperty.SetHasMeasure(false); pointProperty.SetReadOnly(false); pointProperty.SetSpatialContextAssociation("defaultSrs"); properties.Add(pointProperty); MgPropertyDefinitionCollection idProperties = parcelClass.GetIdentityProperties(); idProperties.Add(idProperty); parcelClass.SetDefaultGeometryPropertyName("ParcelLocation"); MgFeatureSchema parcelSchema = new MgFeatureSchema("ParcelLayerSchema", "temporary schema to hold parcel markers"); parcelSchema.GetClasses().Add(parcelClass); MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "defaultSrs", wkt, parcelSchema); featureService.CreateFeatureSource(parcelMarkerDataResId, sdfParams); }
private void button1_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); MgFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgResourceIdentifier fsId = new MgResourceIdentifier(txtFeatureSource.Text); MgStringCollection schemas = featSvc.GetSchemas(fsId); string[] values = new string[schemas.GetCount()]; for (int i = 0; i < schemas.GetCount(); i++) { values[i] = schemas.GetItem(i); } MessageBox.Show(string.Join(Environment.NewLine, values), "Schemas found"); } catch (MgException ex) { MessageBox.Show(ex.ToString(), "Error from MapGuide"); } }
public MarkupEditor(NameValueCollection incomingArgs) { this.args = incomingArgs; this.site = new MgSiteConnection(); this.site.Open(new MgUserInformation(GetParameter(this.args, "SESSION"))); _resourceService = (MgResourceService)this.site.CreateService(MgServiceType.ResourceService); _featureService = (MgFeatureService)this.site.CreateService(MgServiceType.FeatureService); if (!string.IsNullOrEmpty(GetParameter(this.args, "DIR"))) libraryPath = GetParameter(this.args, "DIR"); else { MgMap map = new MgMap(); map.Open(_resourceService, GetParameter(this.args, "MAPNAME")); string path = map.MapDefinition.Path; if (path.ToLower().EndsWith("maps")) path = path.Substring(0, path.Length - 4); /*libraryPath = Path.Combine(String.Format("Library://{0}", path), "Markup/");*/ libraryPath = ConfigurationManager.AppSettings["MarkupLibraryPath"].ToString(); } FeatureHasProjectIdField(); }
public GetClasses(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
public static void EmitLocationResults(MgFeatureService featureService, MgResourceIdentifier locationMarkerDataResId, String mgSessionId, HttpResponse response) { //targets.InnerHtml+="<table class=\"RegText\" border=\"0\" cellspacing=\"0\" width=\"100%\">"; //targets.InnerHtml+="<tr><td class=\"SubTitle\">תוצאות</td></tr>"; MgAgfReaderWriter geometryReaderWriter = new MgAgfReaderWriter(); MgFeatureReader featureReader = featureService.SelectFeatures(locationMarkerDataResId, "LocationMarker", null); while (featureReader.ReadNext()) { String address = featureReader.GetString("Address"); MgByteReader byteReader = featureReader.GetGeometry("Location"); MgPoint point = geometryReaderWriter.Read(byteReader) as MgPoint; double x = point.GetCoordinate().GetX(); double y = point.GetCoordinate().GetY(); // targets.InnerHtml+="<tr><td>"; // targets.InnerHtml+="<img src=\"../images/pushpinblue.jpg\">"; // targets.InnerHtml += "<a href=\"gotopoint.aspx?X=" + x + "&Y=" + y + "&Scale=10000\" target=\"scriptFrame\">X: " + x + ", Y: " + y + "</a></td></tr>"; } featureReader.Close(); //targets.InnerHtml+="</table>"; // targets.InnerHtml+="<form action=\"clearlocationresults.aspx\" method=\"get\" target=\"scriptFrame\">"; //targets.InnerHtml+="<input type=\"hidden\" name=\"SESSION\" value=\"" + mgSessionId + "\">"; // targets.InnerHtml+="<input type=\"button\" class=\"Ctrl\" value=\"נקה תוצאות \" onClick=\"javascript:submit()\">"; //targets.InnerHtml+="</form>"; // targets.InnerHtml+="<hr>"; }
private void btnFindFeaturesInBuffer_Click(object sender, EventArgs e) { MgSelectionBase selection = _viewer.GetSelection(); MgReadOnlyLayerCollection selectedLayers = selection.GetLayers(); if (selectedLayers == null) { MessageBox.Show("Select a parcel"); return; } MgLayerBase parcels = null; for (int i = 0; i < selectedLayers.GetCount(); i++) { MgLayerBase layer = selectedLayers.GetItem(i); if (layer.Name == "Parcels") { parcels = layer; break; } } if (parcels == null) { MessageBox.Show("Select a parcel"); return; } int bufferRingSize = 500; // measured in metres // Set up some objects for coordinate conversion MgMapBase map = _viewer.GetMap(); MgLayerCollection mapLayers = map.GetLayers(); MgMapViewerProvider provider = _viewer.GetProvider(); MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); //Casting to MgdFeatureService because we want to use convenience APIs MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService); string sessionId = Guid.NewGuid().ToString(); String mapWktSrs = map.GetMapSRS(); MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter(); MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory(); MgCoordinateSystem srs = coordinateSystemFactory.Create(mapWktSrs); MgMeasure srsMeasure = srs.GetMeasure(); // Check for a buffer layer. If it exists, delete // the current features. // If it does not exist, create a feature source and // a layer to hold the buffer. BufferHelper helper = new BufferHelper(); MgdLayer bufferLayer = null; int layerIndex = map.GetLayers().IndexOf("Buffer"); if (layerIndex < 0) { // The layer does not exist and must be created. MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource"); helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId); bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId); map.GetLayers().Insert(0, bufferLayer); } else { bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex); bufferLayer.DeleteFeatures("ID like '%'"); } // Check for a parcel marker layer. If it exists, delete // the current features. // If it does not exist, create a feature source and // a layer to hold the parcel markers. MgdLayer parcelMarkerLayer = null; layerIndex = map.GetLayers().IndexOf("ParcelMarker"); if (layerIndex < 0) { MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource"); helper.CreateParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId); parcelMarkerLayer = helper.CreateParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId); map.GetLayers().Insert(0, parcelMarkerLayer); } else { parcelMarkerLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex); parcelMarkerLayer.DeleteFeatures("ID like '%'"); } // Check each layer in the selection. for (int i = 0; i < selectedLayers.GetCount(); i++) { // Only check selected features in the Parcels layer. MgdLayer layer = (MgdLayer)selectedLayers.GetItem(i); if (layer.GetName() == "Parcels") { string geomName = layer.GetFeatureGeometryName(); System.Diagnostics.Trace.TraceInformation("Marking all parcels inside the buffer that are of type 'MFG'"); MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false); // Process each item in the MgFeatureReader. Get the // geometries from all the selected features and // merge them into a single geometry. MgGeometryCollection inputGeometries = new MgGeometryCollection(); while (featureReader.ReadNext()) { MgByteReader featureGeometryData = featureReader.GetGeometry(geomName); MgGeometry featureGeometry = agfReaderWriter.Read(featureGeometryData); inputGeometries.Add(featureGeometry); } MgGeometryFactory geometryFactory = new MgGeometryFactory(); MgGeometry mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries); // Create a buffer from the merged geometries double bufferDist = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize); MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure); // Create a filter to select parcels within the buffer. Combine // a basic filter and a spatial filter to select all parcels // within the buffer that are of type "MFG". MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions(); queryOptions.SetFilter("RTYPE = 'MFG'"); queryOptions.SetSpatialFilter(geomName, bufferGeometry, MgFeatureSpatialOperations.Inside); featureReader = layer.SelectFeatures(queryOptions); // Get the features from the feature source, // determine the centroid of each selected feature, and // add a point to the ParcelMarker layer to mark the // centroid. // Collect all the points into an MgFeatureCommandCollection, // so they can all be added in one operation. MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection(); int inserted = 0; while (featureReader.ReadNext()) { MgByteReader byteReader = featureReader.GetGeometry(geomName); MgGeometry geometry = agfReaderWriter.Read(byteReader); MgPoint point = geometry.GetCentroid(); // Create an insert command for this parcel. MgPropertyCollection properties = new MgPropertyCollection(); properties.Add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.Write(point))); //parcelMarkerCommands.Add(new MgInsertFeatures("ParcelMarkerClass", properties)); MgFeatureReader fr = parcelMarkerLayer.InsertFeatures(properties); fr.Close(); inserted++; } featureReader.Close(); if (inserted == 0) { MessageBox.Show("No parcels within the buffer area match."); return; } // Create a feature in the buffer feature source to show the area covered by the buffer. MgPropertyCollection props = new MgPropertyCollection(); props.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry))); bufferLayer.InsertFeatures(props); // Ensure that the buffer layer is visible and in the legend. bufferLayer.SetVisible(true); bufferLayer.ForceRefresh(); bufferLayer.SetDisplayInLegend(true); parcelMarkerLayer.SetVisible(true); parcelMarkerLayer.ForceRefresh(); MessageBox.Show("Done"); _viewer.RefreshMap(); IMapLegend legend = Shell.Instance.Legend; if (legend != null) { legend.RefreshLegend(); } } } }
private string ApplyTheme(ThemeParams themeParams) { var provider = _viewer.GetProvider(); var map = _viewer.GetMap(); var layers = map.GetLayers(); MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); MgFeatureService featureService = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService); MgResourceIdentifier resId = new MgResourceIdentifier(themeParams.layer.GetFeatureSourceId()); MgResourceIdentifier layerDefResId = themeParams.layer.GetLayerDefinition(); MgByteReader byteReader = resourceService.GetResourceContent(layerDefResId); // Load the Layer Definition and Navigate to the specified <VectorScaleRange> XmlDocument doc = new XmlDocument(); String xmlLayerDef = byteReader.ToString(); doc.LoadXml(xmlLayerDef); XmlNodeList nodeList = doc.GetElementsByTagName("VectorScaleRange"); //NOXLATE XmlElement vectorScaleRangecElement = (XmlElement)nodeList.Item(themeParams.scaleRangeIndex); XmlElement areaTypeStyle = (XmlElement)vectorScaleRangecElement.GetElementsByTagName("AreaTypeStyle").Item(0); //NOXLATE // Remove any existing <AreaRule> elements. XmlNodeList areaRuleList = areaTypeStyle.GetElementsByTagName("AreaRule"); //NOXLATE int count = areaRuleList.Count; for (int i = 0; i < count; i++) { //The areaRuleList shrinks as we remove items, so always //remove the first item (don't use the index i) areaTypeStyle.RemoveChild(areaRuleList.Item(0)); } // Now create the new <AreaRule> elements. String areaRuleTemplate = Properties.Resources.AreaRuleTemplate; MgFeatureAggregateOptions aggregateOptions = new MgFeatureAggregateOptions(); String value = null; String filterText = null; String areaRuleXML = null; XmlDocument areaDoc = null; XmlNode areaNode = null; double portion = 0.0; double increment = (themeParams.numRules > 1) ? 1.0 / (themeParams.numRules - 1) : 1.0; if (THEME_INDIVIDUAL == themeParams.distro) { aggregateOptions.AddComputedProperty("THEME_VALUE", "UNIQUE(\"" + themeParams.property.Name + "\")"); //NOXLATE MgDataReader dataReader = featureService.SelectAggregate(resId, themeParams.layer.GetFeatureClassName(), aggregateOptions); while (dataReader.ReadNext()) { value = Util.GetFeaturePropertyValue(dataReader, "THEME_VALUE"); //NOXLATE filterText = """ + themeParams.property.Name + "" = "; //NOXLATE if (themeParams.property.DataType == MgPropertyType.String) { filterText = filterText + "'" + value + "'"; //NOXLATE } else { filterText = filterText + value; } areaRuleXML = String.Format(areaRuleTemplate, themeParams.property.Name + ":" + value, //NOXLATE filterText, Util.InterpolateColor(portion, themeParams.fillFrom, themeParams.fillTo, themeParams.fillTrans), Util.InterpolateColor(portion, themeParams.borderFrom, themeParams.borderTo, 0)); areaDoc = new XmlDocument(); areaDoc.LoadXml(areaRuleXML); areaNode = doc.ImportNode(areaDoc.DocumentElement, true); areaTypeStyle.AppendChild(areaNode); portion = portion + increment; } dataReader.Close(); } else { var values = new List <string>(); var expr = themeParams.distro + "(\"" + themeParams.property.Name + "\"," + themeParams.numRules + "," + themeParams.minValue + "," + themeParams.maxValue + ")"; //NOXLATE aggregateOptions.AddComputedProperty("THEME_VALUE", expr); //NOXLATE MgDataReader dataReader = featureService.SelectAggregate(resId, themeParams.layer.GetFeatureClassName(), aggregateOptions); while (dataReader.ReadNext()) { value = Util.GetFeaturePropertyValue(dataReader, "THEME_VALUE"); //NOXLATE values.Add(value); } dataReader.Close(); for (int i = 0; i < values.Count - 1; i++) { filterText = """ + themeParams.property.Name + "" >= " + values[i] + " AND "" + themeParams.property.Name; //NOXLATE if (i == values.Count - 1) { filterText = filterText + "" <= " + values[i + 1]; //NOXLATE } else { filterText = filterText + "" < " + values[i + 1]; //NOXLATE } areaRuleXML = String.Format(areaRuleTemplate, themeParams.property.Name + ":" + values[i] + " - " + values[i + 1], //NOXLATE filterText, Util.InterpolateColor(portion, themeParams.fillFrom, themeParams.fillTo, themeParams.fillTrans), Util.InterpolateColor(portion, themeParams.borderFrom, themeParams.borderTo, 0)); areaDoc = new XmlDocument(); areaDoc.LoadXml(areaRuleXML); areaNode = doc.ImportNode(areaDoc.DocumentElement, true); areaTypeStyle.AppendChild(areaNode); portion = portion + increment; } } // Now save our new layer definition to the session and add it to the map. String xmlString = doc.DocumentElement.OuterXml; String uniqueName = Util.MakeUniqueLayerName(map, themeParams.layer.Name, themeParams.themeName); String legendLabel = themeParams.layer.GetLegendLabel(); if (!string.IsNullOrEmpty(themeParams.themeName)) { legendLabel = legendLabel + " (" + themeParams.themeName + ")"; //NOXLATE } MgResourceIdentifier layerResId = new MgResourceIdentifier("Session:" + _sessionId + "//" + uniqueName + ".LayerDefinition"); //NOXLATE resourceService.SetResource(layerResId, new MgByteReader(xmlString, "text/xml"), null); //NOXLATE var newLayer = provider.CreateLayer(layerResId); newLayer.SetName(uniqueName); newLayer.SetLegendLabel(legendLabel); newLayer.SetDisplayInLegend(themeParams.layer.GetDisplayInLegend()); newLayer.SetVisible(true); newLayer.SetSelectable(themeParams.layer.GetSelectable()); //HACK: This has to be true otherwise owner-drawn nodes will not display its children (the theme rules) provider.SetLayerExpandInLegend(newLayer, true); layers.Insert(layers.IndexOf(themeParams.layer), newLayer); //map.Save(resourceService); return(uniqueName); }
public GetProviderCapabilities(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
protected override void SetupExecutors(string dbPath) { //NOTE: We can't share the SqliteVm instance among our executor objects as this messes up query results //we must be able to re-create a new SqliteVm for each executor, so we pass down the db path _executors = new Dictionary <string, ITestExecutor>(); MgResourceService resSvc = (MgResourceService)_conn.CreateService(MgServiceType.ResourceService); MgFeatureService featSvc = (MgFeatureService)_conn.CreateService(MgServiceType.FeatureService); MgDrawingService drawSvc = (MgDrawingService)_conn.CreateService(MgServiceType.DrawingService); var site = _conn.GetSite(); var admin = new MgServerAdmin(); admin.Open(_userInfo); var wlCreator = new MgWebLayoutCreator(resSvc); var creator = new MgMapCreator(_conn, resSvc); var sessionCreator = new MgSessionCreator(_conn); var sessionApply = new MgApplySession(_userInfo); var session = new MgSession(); //Resource Service _executors[typeof(Operations.ApplyResourcePackage).Name.ToUpper()] = new Operations.ApplyResourcePackage(resSvc, dbPath); _executors[typeof(Operations.ChangeResourceOwner).Name.ToUpper()] = new Operations.ChangeResourceOwner(resSvc, dbPath); _executors[typeof(Operations.CopyResource).Name.ToUpper()] = new Operations.CopyResource(resSvc, dbPath); _executors[typeof(Operations.DeleteResource).Name.ToUpper()] = new Operations.DeleteResource(resSvc, dbPath); _executors[typeof(Operations.DeleteResourceData).Name.ToUpper()] = new Operations.DeleteResourceData(resSvc, dbPath); _executors[typeof(Operations.EnumerateResourceData).Name.ToUpper()] = new Operations.EnumerateResourceData(resSvc, dbPath); _executors[typeof(Operations.EnumerateResourceReferences).Name.ToUpper()] = new Operations.EnumerateResourceReferences(resSvc, dbPath); _executors[typeof(Operations.EnumerateResources).Name.ToUpper()] = new Operations.EnumerateResources(resSvc, dbPath); _executors[typeof(Operations.GetRepositoryContent).Name.ToUpper()] = new Operations.GetRepositoryContent(resSvc, dbPath); _executors[typeof(Operations.GetRepositoryHeader).Name.ToUpper()] = new Operations.GetRepositoryHeader(resSvc, dbPath); _executors[typeof(Operations.GetResourceContent).Name.ToUpper()] = new Operations.GetResourceContent(resSvc, dbPath); _executors[typeof(Operations.GetResourceData).Name.ToUpper()] = new Operations.GetResourceData(resSvc, dbPath); _executors[typeof(Operations.GetResourceHeader).Name.ToUpper()] = new Operations.GetResourceHeader(resSvc, dbPath); _executors[typeof(Operations.InheritPermissionsFrom).Name.ToUpper()] = new Operations.InheritPermissionsFrom(resSvc, dbPath); _executors[typeof(Operations.MoveResource).Name.ToUpper()] = new Operations.MoveResource(resSvc, dbPath); _executors[typeof(Operations.RenameResourceData).Name.ToUpper()] = new Operations.RenameResourceData(resSvc, dbPath); _executors[typeof(Operations.SetResource).Name.ToUpper()] = new Operations.SetResource(resSvc, dbPath); _executors[typeof(Operations.SetResourceData).Name.ToUpper()] = new Operations.SetResourceData(resSvc, dbPath); _executors[typeof(Operations.UpdateRepository).Name.ToUpper()] = new Operations.UpdateRepository(resSvc, dbPath); //Feature Service _executors[typeof(Operations.DescribeFeatureSchema).Name.ToUpper()] = new Operations.DescribeFeatureSchema(featSvc, dbPath); _executors[typeof(Operations.ExecuteSqlQuery).Name.ToUpper()] = new Operations.ExecuteSqlQuery(featSvc, dbPath); _executors[typeof(Operations.GetClasses).Name.ToUpper()] = new Operations.GetClasses(featSvc, dbPath); _executors[typeof(Operations.GetConnectionPropertyValues).Name.ToUpper()] = new Operations.GetConnectionPropertyValues(featSvc, dbPath); _executors[typeof(Operations.GetFeatureProviders).Name.ToUpper()] = new Operations.GetFeatureProviders(featSvc, dbPath); _executors[typeof(Operations.GetLongTransactions).Name.ToUpper()] = new Operations.GetLongTransactions(featSvc, dbPath); _executors[typeof(Operations.GetProviderCapabilities).Name.ToUpper()] = new Operations.GetProviderCapabilities(featSvc, dbPath); _executors[typeof(Operations.GetSchemas).Name.ToUpper()] = new Operations.GetSchemas(featSvc, dbPath); _executors[typeof(Operations.GetSpatialContexts).Name.ToUpper()] = new Operations.GetSpatialContexts(featSvc, dbPath); _executors[typeof(Operations.SelectAggregates).Name.ToUpper()] = new Operations.SelectAggregates(featSvc, dbPath); _executors[typeof(Operations.SelectFeatures).Name.ToUpper()] = new Operations.SelectFeatures(featSvc, dbPath); _executors[typeof(Operations.SetLongTransaction).Name.ToUpper()] = new Operations.SetLongTransaction(featSvc, dbPath, sessionCreator, sessionApply); _executors[typeof(Operations.TestConnection).Name.ToUpper()] = new Operations.TestConnection(featSvc, dbPath); //Map and Layers _executors[typeof(Operations.AddLayerGroup).Name.ToUpper()] = new Operations.AddLayerGroup(resSvc, dbPath, creator); _executors[typeof(Operations.AddLayer).Name.ToUpper()] = new Operations.AddLayer(resSvc, dbPath, creator); _executors[typeof(Operations.GetCoordinateSystem).Name.ToUpper()] = new Operations.GetCoordinateSystem(resSvc, dbPath, creator); _executors[typeof(Operations.GetDataExtent).Name.ToUpper()] = new Operations.GetDataExtent(resSvc, dbPath, creator); _executors[typeof(Operations.GetDisplayInLegend).Name.ToUpper()] = new Operations.GetDisplayInLegend(resSvc, dbPath, creator); _executors[typeof(Operations.GetLayerFeatureClass).Name.ToUpper()] = new Operations.GetLayerFeatureClass(resSvc, dbPath, creator); _executors[typeof(Operations.GetLayerFeatureSource).Name.ToUpper()] = new Operations.GetLayerFeatureSource(resSvc, dbPath, creator); _executors[typeof(Operations.GetLayerDefinition).Name.ToUpper()] = new Operations.GetLayerDefinition(resSvc, dbPath, creator); _executors[typeof(Operations.GetGroups).Name.ToUpper()] = new Operations.GetGroups(resSvc, dbPath, creator); _executors[typeof(Operations.GetLayers).Name.ToUpper()] = new Operations.GetLayers(resSvc, dbPath, creator); _executors[typeof(Operations.GetLayerVisibility).Name.ToUpper()] = new Operations.GetLayerVisibility(resSvc, dbPath, creator); _executors[typeof(Operations.GetLegendLabel).Name.ToUpper()] = new Operations.GetLegendLabel(resSvc, dbPath, creator); _executors[typeof(Operations.GetMapExtent).Name.ToUpper()] = new Operations.GetMapExtent(resSvc, dbPath, creator); _executors[typeof(Operations.GetMapName).Name.ToUpper()] = new Operations.GetMapName(resSvc, dbPath, creator); _executors[typeof(Operations.GetViewCenter).Name.ToUpper()] = new Operations.GetViewCenter(resSvc, dbPath, creator); _executors[typeof(Operations.GetViewScale).Name.ToUpper()] = new Operations.GetViewScale(resSvc, dbPath, creator); _executors[typeof(Operations.HideGroup).Name.ToUpper()] = new Operations.HideGroup(resSvc, dbPath, creator); _executors[typeof(Operations.IsLayerVisible).Name.ToUpper()] = new Operations.IsLayerVisible(resSvc, dbPath, creator); _executors[typeof(Operations.LayerExists).Name.ToUpper()] = new Operations.LayerExists(resSvc, dbPath, creator); _executors[typeof(Operations.RemoveGroup).Name.ToUpper()] = new Operations.RemoveGroup(resSvc, dbPath, creator); _executors[typeof(Operations.ShowGroup).Name.ToUpper()] = new Operations.ShowGroup(resSvc, dbPath, creator); //Drawing Service _executors[typeof(Operations.DescribeDrawing).Name.ToUpper()] = new Operations.DescribeDrawing(drawSvc, dbPath); _executors[typeof(Operations.GetDrawing).Name.ToUpper()] = new Operations.GetDrawing(drawSvc, dbPath); _executors[typeof(Operations.EnumerateDrawingLayers).Name.ToUpper()] = new Operations.EnumerateDrawingLayers(drawSvc, dbPath); _executors[typeof(Operations.GetDrawingLayer).Name.ToUpper()] = new Operations.GetDrawingLayer(drawSvc, dbPath); _executors[typeof(Operations.GetDrawingSection).Name.ToUpper()] = new Operations.GetDrawingSection(drawSvc, dbPath); _executors[typeof(Operations.EnumerateDrawingSections).Name.ToUpper()] = new Operations.EnumerateDrawingSections(drawSvc, dbPath); _executors[typeof(Operations.EnumerateDrawingSectionResources).Name.ToUpper()] = new Operations.EnumerateDrawingSectionResources(drawSvc, dbPath); _executors[typeof(Operations.GetDrawingSectionResource).Name.ToUpper()] = new Operations.GetDrawingSectionResource(drawSvc, dbPath); //Mapping Service //Rendering Service //Server Admin _executors[typeof(Operations.Offline).Name.ToUpper()] = new Operations.Offline(admin, dbPath); _executors[typeof(Operations.Online).Name.ToUpper()] = new Operations.Online(admin, dbPath); _executors[typeof(Operations.GetLog).Name.ToUpper()] = new Operations.GetLog(admin, dbPath); _executors[typeof(Operations.GetLogByDate).Name.ToUpper()] = new Operations.GetLogByDate(admin, dbPath); _executors[typeof(Operations.ClearLog).Name.ToUpper()] = new Operations.ClearLog(admin, dbPath); _executors[typeof(Operations.DeleteLog).Name.ToUpper()] = new Operations.DeleteLog(admin, dbPath); _executors[typeof(Operations.RenameLog).Name.ToUpper()] = new Operations.RenameLog(admin, dbPath); _executors[typeof(Operations.EnumeratePackages).Name.ToUpper()] = new Operations.EnumeratePackages(admin, dbPath); _executors[typeof(Operations.DeletePackage).Name.ToUpper()] = new Operations.DeletePackage(admin, dbPath); _executors[typeof(Operations.LoadPackage).Name.ToUpper()] = new Operations.LoadPackage(admin, dbPath); _executors[typeof(Operations.GetPackageStatus).Name.ToUpper()] = new Operations.GetPackageStatus(admin, dbPath); _executors[typeof(Operations.GetPackageLog).Name.ToUpper()] = new Operations.GetPackageLog(admin, dbPath); //Site Service _executors[typeof(Operations.CreateSession).Name.ToUpper()] = new Operations.CreateSession(site, dbPath, session); _executors[typeof(Operations.DestroySession).Name.ToUpper()] = new Operations.DestroySession(site, dbPath); _executors[typeof(Operations.GetUserForSession).Name.ToUpper()] = new Operations.GetUserForSession(site, dbPath, session); _executors[typeof(Operations.EnumerateUsers).Name.ToUpper()] = new Operations.EnumerateUsers(site, dbPath); _executors[typeof(Operations.AddUser).Name.ToUpper()] = new Operations.AddUser(site, dbPath); _executors[typeof(Operations.UpdateUser).Name.ToUpper()] = new Operations.UpdateUser(site, dbPath); _executors[typeof(Operations.DeleteUsers).Name.ToUpper()] = new Operations.DeleteUsers(site, dbPath); _executors[typeof(Operations.GrantRoleMembershipsToUsers).Name.ToUpper()] = new Operations.GrantRoleMembershipsToUsers(site, dbPath); _executors[typeof(Operations.RevokeRoleMembershipsFromUsers).Name.ToUpper()] = new Operations.RevokeRoleMembershipsFromUsers(site, dbPath); _executors[typeof(Operations.GrantGroupMembershipsToUsers).Name.ToUpper()] = new Operations.GrantGroupMembershipsToUsers(site, dbPath); _executors[typeof(Operations.RevokeGroupMembershipsFromUsers).Name.ToUpper()] = new Operations.RevokeGroupMembershipsFromUsers(site, dbPath); _executors[typeof(Operations.EnumerateGroups).Name.ToUpper()] = new Operations.EnumerateGroups(site, dbPath); _executors[typeof(Operations.EnumerateGroups2).Name.ToUpper()] = new Operations.EnumerateGroups2(site, dbPath); _executors[typeof(Operations.EnumerateRoles2).Name.ToUpper()] = new Operations.EnumerateRoles2(site, dbPath); _executors[typeof(Operations.AddGroup).Name.ToUpper()] = new Operations.AddGroup(site, dbPath); _executors[typeof(Operations.UpdateGroup).Name.ToUpper()] = new Operations.UpdateGroup(site, dbPath); _executors[typeof(Operations.DeleteGroups).Name.ToUpper()] = new Operations.DeleteGroups(site, dbPath); _executors[typeof(Operations.GrantRoleMembershipsToGroups).Name.ToUpper()] = new Operations.GrantRoleMembershipsToGroups(site, dbPath); _executors[typeof(Operations.RevokeRoleMembershipsFromGroups).Name.ToUpper()] = new Operations.RevokeRoleMembershipsFromGroups(site, dbPath); _executors[typeof(Operations.EnumerateRoles).Name.ToUpper()] = new Operations.EnumerateRoles(site, dbPath); _executors[typeof(Operations.EnumerateServers).Name.ToUpper()] = new Operations.EnumerateServers(site, dbPath); _executors[typeof(Operations.AddServer).Name.ToUpper()] = new Operations.AddServer(site, dbPath); _executors[typeof(Operations.UpdateServer).Name.ToUpper()] = new Operations.UpdateServer(site, dbPath); _executors[typeof(Operations.RemoveServer).Name.ToUpper()] = new Operations.RemoveServer(site, dbPath); //Web Layout _executors[typeof(Operations.WL_GetTitle).Name.ToUpper()] = new Operations.WL_GetTitle(wlCreator, dbPath); _executors[typeof(Operations.WL_GetMapDefinition).Name.ToUpper()] = new Operations.WL_GetMapDefinition(wlCreator, dbPath); _executors[typeof(Operations.WL_GetScale).Name.ToUpper()] = new Operations.WL_GetScale(wlCreator, dbPath); _executors[typeof(Operations.WL_GetCenter).Name.ToUpper()] = new Operations.WL_GetCenter(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowToolbar).Name.ToUpper()] = new Operations.WL_ShowToolbar(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowStatusbar).Name.ToUpper()] = new Operations.WL_ShowStatusbar(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowTaskpane).Name.ToUpper()] = new Operations.WL_ShowTaskpane(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowTaskbar).Name.ToUpper()] = new Operations.WL_ShowTaskbar(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowLegend).Name.ToUpper()] = new Operations.WL_ShowLegend(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowProperties).Name.ToUpper()] = new Operations.WL_ShowProperties(wlCreator, dbPath); _executors[typeof(Operations.WL_GetTaskPaneWidth).Name.ToUpper()] = new Operations.WL_GetTaskPaneWidth(wlCreator, dbPath); _executors[typeof(Operations.WL_GetInformationPaneWidth).Name.ToUpper()] = new Operations.WL_GetInformationPaneWidth(wlCreator, dbPath); _executors[typeof(Operations.WL_GetInitialTaskUrl).Name.ToUpper()] = new Operations.WL_GetInitialTaskUrl(wlCreator, dbPath); _executors[typeof(Operations.WL_ShowContextMenu).Name.ToUpper()] = new Operations.WL_ShowContextMenu(wlCreator, dbPath); _executors[typeof(Operations.WL_TestUiItem).Name.ToUpper()] = new Operations.WL_TestUiItem(wlCreator, dbPath); _executors[typeof(Operations.WL_HomeTooltip).Name.ToUpper()] = new Operations.WL_HomeTooltip(wlCreator, dbPath); _executors[typeof(Operations.WL_HomeDescription).Name.ToUpper()] = new Operations.WL_HomeDescription(wlCreator, dbPath); _executors[typeof(Operations.WL_BackTooltip).Name.ToUpper()] = new Operations.WL_BackTooltip(wlCreator, dbPath); _executors[typeof(Operations.WL_BackDescription).Name.ToUpper()] = new Operations.WL_BackDescription(wlCreator, dbPath); _executors[typeof(Operations.WL_ForwardTooltip).Name.ToUpper()] = new Operations.WL_ForwardTooltip(wlCreator, dbPath); _executors[typeof(Operations.WL_ForwardDescription).Name.ToUpper()] = new Operations.WL_ForwardDescription(wlCreator, dbPath); _executors[typeof(Operations.WL_TasksName).Name.ToUpper()] = new Operations.WL_TasksName(wlCreator, dbPath); _executors[typeof(Operations.WL_TasksTooltip).Name.ToUpper()] = new Operations.WL_TasksTooltip(wlCreator, dbPath); _executors[typeof(Operations.WL_TasksDescription).Name.ToUpper()] = new Operations.WL_TasksDescription(wlCreator, dbPath); }
public TestConnection(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
public DescribeFeatureSchema(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
public GetConnectionPropertyValues(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
public void CreateParcelMarkerFeatureSource(MgFeatureService featureService, String wkt, MgResourceIdentifier parcelMarkerDataResId) { MgClassDefinition parcelClass = new MgClassDefinition(); parcelClass.SetName("ParcelMarkerClass"); MgPropertyDefinitionCollection properties = parcelClass.GetProperties(); MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID"); idProperty.SetDataType(MgPropertyType.Int32); idProperty.SetReadOnly(true); idProperty.SetNullable(false); idProperty.SetAutoGeneration(true); properties.Add(idProperty); MgGeometricPropertyDefinition pointProperty = new MgGeometricPropertyDefinition("ParcelLocation"); pointProperty.SetGeometryTypes(MgGeometryType.Point); pointProperty.SetHasElevation(false); pointProperty.SetHasMeasure(false); pointProperty.SetReadOnly(false); pointProperty.SetSpatialContextAssociation("defaultSrs"); properties.Add(pointProperty); MgPropertyDefinitionCollection idProperties = parcelClass.GetIdentityProperties(); idProperties.Add(idProperty); parcelClass.SetDefaultGeometryPropertyName("ParcelLocation"); MgFeatureSchema parcelSchema = new MgFeatureSchema("ParcelLayerSchema", "temporary schema to hold parcel markers"); parcelSchema.GetClasses().Add(parcelClass); MgCreateSdfParams sdfParams = new MgCreateSdfParams("defaultSrs", wkt, parcelSchema); featureService.CreateFeatureSource(parcelMarkerDataResId, sdfParams); }
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); } }
void CreateLocationMarkerFeatureSource(MgFeatureService featureService, MgResourceIdentifier locationMarkerDataResId) { String ll84Wkt = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.25722293287],TOWGS84[0,0,0,0,0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degrees\",1]]"; MgClassDefinition locationClass = new MgClassDefinition(); locationClass.SetName("LocationMarker"); MgPropertyDefinitionCollection properties = locationClass.GetProperties(); MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID"); idProperty.SetDataType(MgPropertyType.Int32); idProperty.SetReadOnly(true); idProperty.SetNullable(false); idProperty.SetAutoGeneration(true); properties.Add(idProperty); MgDataPropertyDefinition addressProperty = new MgDataPropertyDefinition("Address"); addressProperty.SetDataType(MgPropertyType.String); addressProperty.SetLength(512); properties.Add(addressProperty); MgGeometricPropertyDefinition locationProperty = new MgGeometricPropertyDefinition("Location"); locationProperty.SetGeometryTypes(MgGeometryType.Point); locationProperty.SetHasElevation(false); locationProperty.SetHasMeasure(false); locationProperty.SetReadOnly(false); locationProperty.SetSpatialContextAssociation("LL84"); properties.Add(locationProperty); MgPropertyDefinitionCollection idProperties = locationClass.GetIdentityProperties(); idProperties.Add(idProperty); locationClass.SetDefaultGeometryPropertyName("Location"); MgFeatureSchema locationSchema = new MgFeatureSchema(); locationSchema.SetName("LocationMarkerSchema"); locationSchema.GetClasses().Add(locationClass); MgCreateSdfParams sdfParams = new MgCreateSdfParams("LL84", ll84Wkt, locationSchema); featureService.CreateFeatureSource(locationMarkerDataResId, sdfParams); }
public RedlineRegistry(string sessionID, MgResourceService resSvc, MgFeatureService featSvc) { _sessionID = sessionID; _resSvc = resSvc; _featSvc = featSvc; }
protected FeatureServiceOperationExecutor(MgFeatureService featSvc, string unitTestVm) : base(typeof(T).Name.ToUpper(), ApiTypes.Platform, unitTestVm) { _featureService = featSvc; }
public GetLongTransactions(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
//--------------------------------------------------------------------------------------- // // ���ܣ�����һ����ΪtempParcel��Ҫ���� // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- private void createTempParcelFeatureSource(MgFeatureService featureService, MgResourceIdentifier resId) { MgClassDefinition parcelClass = null; MgPropertyDefinitionCollection props = null; string ll84Wkt = ""; //����Ҫ���� ll84Wkt = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.25722293287],TOWGS84[0,0,0,0,0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degrees\",1]]"; parcelClass = new MgClassDefinition(); parcelClass.SetName("tempParcel"); props = parcelClass.GetProperties(); //����Ҫ���ඨ��ı�ʶ���� MgDataPropertyDefinition id = new MgDataPropertyDefinition("ID"); id.SetDataType(MgPropertyType.Int32); id.SetReadOnly(true); id.SetNullable(false); id.SetAutoGeneration(true); props.Add(id); MgPropertyDefinitionCollection idProps = parcelClass.GetIdentityProperties(); idProps.Add(id); //����Ҫ���ඨ��ļ������� MgGeometricPropertyDefinition geom = new MgGeometricPropertyDefinition("GEOM"); geom.SetGeometryTypes(MgFeatureGeometricType.Surface); geom.SetHasElevation(false); geom.SetHasMeasure(false); geom.SetSpatialContextAssociation("LL84"); props.Add(geom); parcelClass.SetDefaultGeometryPropertyName("GEOM"); //����Ҫ���ඨ��һ������� MgDataPropertyDefinition acre = new MgDataPropertyDefinition("ACRE"); acre.SetDataType(MgPropertyType.String); acre.SetLength(256); props.Add(acre); MgDataPropertyDefinition billingAddr = new MgDataPropertyDefinition("BILLADDR"); billingAddr.SetDataType(MgPropertyType.String); billingAddr.SetLength(64); props.Add(billingAddr); MgDataPropertyDefinition desc1 = new MgDataPropertyDefinition("DESC1"); desc1.SetDataType(MgPropertyType.String); desc1.SetLength(64); props.Add(desc1); MgDataPropertyDefinition desc2 = new MgDataPropertyDefinition("DESC2"); desc2.SetDataType(MgPropertyType.String); desc2.SetLength(64); props.Add(desc2); MgDataPropertyDefinition desc3 = new MgDataPropertyDefinition("DESC3"); desc3.SetDataType(MgPropertyType.String); desc3.SetLength(64); props.Add(desc3); MgDataPropertyDefinition desc4 = new MgDataPropertyDefinition("DESC4"); desc4.SetDataType(MgPropertyType.String); desc4.SetLength(64); props.Add(desc4); MgDataPropertyDefinition lotDimension = new MgDataPropertyDefinition("LOTDIM"); lotDimension.SetDataType(MgPropertyType.String); lotDimension.SetLength(32); props.Add(lotDimension); MgDataPropertyDefinition sqft = new MgDataPropertyDefinition("SQFT"); sqft.SetDataType(MgPropertyType.Int32); props.Add(sqft); MgDataPropertyDefinition owner = new MgDataPropertyDefinition("OWNER"); owner.SetDataType(MgPropertyType.String); owner.SetLength(64); props.Add(owner); MgDataPropertyDefinition zone = new MgDataPropertyDefinition("ZONE"); zone.SetDataType(MgPropertyType.String); zone.SetLength(32); props.Add(zone); // ����ģʽ MgFeatureSchema schema = new MgFeatureSchema(); schema.SetName("SchemaParcels"); schema.GetClasses().Add(parcelClass); MgCreateSdfParams sdfParams = new MgCreateSdfParams("LL84", ll84Wkt, schema); featureService.CreateFeatureSource(resId, sdfParams); // }
private void btnCreateBuffer_Click(object sender, EventArgs e) { MgSelectionBase selection = _viewer.GetSelection(); MgReadOnlyLayerCollection layers = selection.GetLayers(); if (layers == null) { MessageBox.Show("Select a parcel"); return; } MgLayerBase parcels = null; for (int i = 0; i < layers.GetCount(); i++) { MgLayerBase layer = layers.GetItem(i); if (layer.Name == "Parcels") { parcels = layer; break; } } if (parcels == null) { MessageBox.Show("Select a parcel"); return; } int bufferRingSize = 100; // measured in metres int bufferRingCount = 5; // Set up some objects for coordinate conversion MgMapBase map = _viewer.GetMap(); MgLayerCollection mapLayers = map.GetLayers(); MgMapViewerProvider provider = _viewer.GetProvider(); MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); //Casting to MgdFeatureService because we want to use convenience APIs MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService); String mapWktSrs = map.GetMapSRS(); MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter(); MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory(); MgCoordinateSystem srs = coordinateSystemFactory.Create(mapWktSrs); MgMeasure srsMeasure = srs.GetMeasure(); string sessionId = Guid.NewGuid().ToString(); BufferHelper helper = new BufferHelper(); // Check for a buffer layer. If it exists, delete // the current features. // If it does not exist, create a feature source and // a layer to hold the buffer. MgdLayer bufferLayer = null; int layerIndex = mapLayers.IndexOf("Buffer"); if (layerIndex < 0) { // The layer does not exist and must be created. MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource"); helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId); bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId); mapLayers.Insert(0, bufferLayer); } else { bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex); bufferLayer.DeleteFeatures("ID like '%'"); } // Get the selected features from the MgSelection object MgFeatureReader featureReader = selection.GetSelectedFeatures(parcels, parcels.GetFeatureClassName(), false); // Process each item in the MgFeatureReader. Get the // geometries from all the selected features and // merge them into a single geometry. MgGeometryCollection inputGeometries = new MgGeometryCollection(); while (featureReader.ReadNext()) { MgByteReader featureGeometryData = featureReader.GetGeometry(parcels.GetFeatureGeometryName()); MgGeometry featureGeometry = agfReaderWriter.Read(featureGeometryData); inputGeometries.Add(featureGeometry); } MgGeometryFactory geometryFactory = new MgGeometryFactory(); MgGeometry mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries); // Add buffer features to the temporary feature source. // Create multiple concentric buffers to show area. // If the stylization for the layer draws the features // partially transparent, the concentric rings will be // progressively darker towards the center. // The stylization is set in the layer template file, which // is used in function CreateBufferLayer(). for (int bufferRing = 0; bufferRing < bufferRingCount; bufferRing++) { double bufferDist = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize * (bufferRing + 1)); MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure); MgPropertyCollection properties = new MgPropertyCollection(); properties.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry))); MgFeatureReader fr = bufferLayer.InsertFeatures(properties); fr.Close(); } bufferLayer.SetVisible(true); bufferLayer.ForceRefresh(); bufferLayer.SetDisplayInLegend(true); MessageBox.Show("Buffer created"); _viewer.RefreshMap(); IMapLegend legend = Shell.Instance.Legend; if (legend != null) { legend.RefreshLegend(); } }
public GetSpatialContexts(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }
public SetLongTransaction(MgFeatureService featSvc, string unitTestVm, ISessionCreator creator, IApplySession apply) : base(featSvc, unitTestVm) { _creator = creator; _apply = apply; }
//--------------------------------------------------------------------------------------- // // ���ܣ������ѯ��� // // ���ߣ� // // ���ڣ� 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; }
public GetSchemas(MgFeatureService featSvc, string unitTestVm) : base(featSvc, unitTestVm) { }