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); }
private void CreateSdf(MgResourceIdentifier sdfResId) { MgFeatureSchema schema = new MgFeatureSchema("Maintenance", ""); MgCreateSdfParams sdfParams = new MgCreateSdfParams("Main", this._helper.Map.MapSRS, schema); schema.GetClasses().Add(CreateMaintenanceClass(false)); schema.GetClasses().Add(CreateMaintenanceClass(true)); schema.GetClasses().Add(CreateFieldsOrderClass()); this._helper.FeatureService.CreateFeatureSource(sdfResId, sdfParams); this.SetOrder(); }
public bool ShowSpatialFilter() { bool result = true; MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]); MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource"); MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgFeatureService featureService = siteConnection.CreateService(MgServiceType.FeatureService) as MgFeatureService; MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection(); MgMap map = new MgMap(); map.Open(resourceService, Request["MAPNAME"]); MgLayer layer = null; MgLayerCollection layers = map.GetLayers(); if (layers.Contains("_QuerySpatialFilter")) { layer = (MgLayer)layers.GetItem("_QuerySpatialFilter"); //updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0")); } else { // Create the Feature Source (SDF) MgFeatureSchema sdfSchema = this.CreateFilterSchema(); MgCreateSdfParams sdfParams = new MgCreateSdfParams("MAPCS", map.GetMapSRS(), sdfSchema); featureService.CreateFeatureSource(sdfResId, sdfParams); // Create the Layer MgResourceIdentifier layerResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.LayerDefinition"); String layerDefinition = File.ReadAllText(GetQueryXmlTemplatePath()); layerDefinition = layerDefinition.Replace("%s", sdfResId.ToString()); MgByteReader reader = new MgByteReader(layerDefinition, "text/xml"); resourceService.SetResource(layerResId, reader, null); layer = new MgLayer(layerResId, resourceService); layer.SetName("_QuerySpatialFilter"); layer.SetLegendLabel("תחום זמני"); layer.SetDisplayInLegend(true); layer.SetSelectable(true); layer.ForceRefresh(); layer.NeedsRefresh(); layers.Insert(0, layer); } // Make the layer visible layer.SetVisible(true); map.Save(resourceService); // Add the geometry to the filter feature source MgPolygon polygon = this.CreatePolygonFromGeomText(Request["GEOMTEXT"].ToString()); MgAgfReaderWriter agfWriter = new MgAgfReaderWriter(); MgByteReader byteReader = agfWriter.Write(polygon); MgPropertyCollection propertyValues = new MgPropertyCollection(); propertyValues.Add(new MgGeometryProperty("Geometry", byteReader)); try { updateCommands.Add(new MgInsertFeatures("Filter", propertyValues)); featureService.UpdateFeatures(sdfResId, updateCommands, false); } catch { } return result; }
public void CreateMarkup(string mgSessionId,string mgMap) { //Response.Write("CreateMarkup" ); MgUserInformation userInfo = new MgUserInformation(mgSessionId); MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgMap map = new MgMap(); map.Open(resourceService, mgMap); // map.Open(resourceService, GetParameter(args, "MAPNAME")); // Create the Markup Feature Source (SDF) MgResourceIdentifier markupSdfResId = new MgResourceIdentifier(libraryPath + GetParameter(this.args, "MARKUPNAME") + ".FeatureSource"); MgFeatureSchema markupSchema = MarkupSchemaFactory.CreateMarkupSchema(); MgCreateSdfParams sdfParams = new MgCreateSdfParams("XY-M", map.MapSRS, markupSchema); featureService.CreateFeatureSource(markupSdfResId, sdfParams); String url = "concat('" + GetParameter(this.args, "MARKUPURL") + "', concat('?key=', "ID"))"; //Link to ProjectManager /* if (GetParameter(this.args, "LINKTOPROJECTMANAGER").ToLower() == "on" && !String.IsNullOrEmpty(GetParameter(this.args, "ProjectCollectionName")) && GetParameter(this.args, "ProjectCollectionName") != "áçø îøùéîä") { string projectCollectionName = GetParameter(this.args, "ProjectCollectionName"); if (projectCollectionName == "àçø...") { projectCollectionName = GetParameter(this.args, "ProjectCollectionOtherName"); } int projectId = 0; using (var conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ProjectManagerConnectionString"].ConnectionString)) { var cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO ProjectCollections(LayoutId, FeatureId, ProjectCollectionName) VALUES(@LayoutId, @FeatureId, @ProjectCollectionName); SELECT @@IDENTITY AS [NEWID]"; cmd.CommandType = System.Data.CommandType.Text; var layoutIdParam = new System.Data.SqlClient.SqlParameter("@LayoutId", System.Data.SqlDbType.NVarChar, 255); layoutIdParam.Value = GetParameter(args, "LAYOUT"); cmd.Parameters.Add(layoutIdParam); var featureIdParam = new System.Data.SqlClient.SqlParameter("@FeatureId", System.Data.SqlDbType.NVarChar, 255); featureIdParam.Value = markupSdfResId.ToString(); cmd.Parameters.Add(featureIdParam); var pcNameParam = new System.Data.SqlClient.SqlParameter("@ProjectCollectionName", System.Data.SqlDbType.NVarChar, 50); pcNameParam.Value = projectCollectionName; cmd.Parameters.Add(pcNameParam); conn.Open(); //projectId = (int)cmd.ExecuteScalar(); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { projectId = Convert.ToInt32(reader[0]); } } } string host = HttpContext.Current.Request.Url.Host; url = String.Format("concat('http://{0}/MgExtensions/ProjectManager/default.aspx?ProjectId={1}&UID=', \"UID\")", host, projectId); } */ // Create the Markup Layer Definition String hexFgTransparency = String.Format("{0:X2}", 255 * (100 - Int32.Parse(GetParameter(this.args, "FILLTRANSPARENCY"))) / 100); // Convert % to an alpha value String hexBgTransparency = GetParameter(this.args, "FILLBACKTRANS").Length > 0 ? "FF" : "00"; // All or nothing String bold = GetParameter(this.args, "LABELBOLD").Length > 0 ? "true" : "false"; String italic = GetParameter(this.args, "LABELITALIC").Length > 0 ? "true" : "false"; String underline = GetParameter(this.args, "LABELUNDERLINE").Length > 0 ? "true" : "false"; String markupLayerDefinition = File.ReadAllText(HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "Extensions\\markup\\templates\\markuplayerdefinition.xml"); markupLayerDefinition = String.Format(markupLayerDefinition, markupSdfResId.ToString(), //<ResourceId> - Feature Source GetParameter(this.args, "LABELSIZEUNITS"), //<Unit> - Mark Label GetParameter(this.args, "LABELFONTSIZE"), //<SizeX> - Mark Label Size GetParameter(this.args, "LABELFONTSIZE"), //<SizeY> - Mark Label Size "FF" + GetParameter(this.args, "LABELFORECOLOR"), //<ForegroundColor> - Mark Label "FF" + GetParameter(this.args, "LABELBACKCOLOR"), //<BackgroundColor> - Mark Label GetParameter(this.args, "LABELBACKSTYLE"), //<BackgroundStyle> - Mark Label bold, //<Bold> - Mark Label italic, //<Bold> - Mark Label underline, //<Underlined> - Mark Label GetParameter(this.args, "MARKERSIZEUNITS"), //<Unit> - Mark GetParameter(this.args, "MARKERSIZE"), //<SizeX> - Mark GetParameter(this.args, "MARKERSIZE"), //<SizeY> - Mark GetParameter(this.args, "MARKERTYPE"), //<Shape> - Mark "FF" + GetParameter(this.args, "MARKERCOLOR"), //<ForegroundColor> - Mark "FF" + GetParameter(this.args, "MARKERCOLOR"), //<Color> - Mark GetParameter(this.args, "LABELSIZEUNITS"), //<Unit> - Line Label GetParameter(this.args, "LABELFONTSIZE"), //<SizeX> - Line Label Size GetParameter(this.args, "LABELFONTSIZE"), //<SizeY> - Line Label Size "FF" + GetParameter(this.args, "LABELFORECOLOR"), //<ForegroundColor> - Line Label "FF" + GetParameter(this.args, "LABELBACKCOLOR"), //<BackgroundColor> - Line Label GetParameter(this.args, "LABELBACKSTYLE"), //<BackgroundStyle> - Line Label bold, //<Bold> - Line Label italic, //<Bold> - Line Label underline, //<Underlined> - Line Label GetParameter(this.args, "LINEPATTERN"), //<LineStyle> - Line GetParameter(this.args, "LINETHICKNESS"), //<Thickness> - Line "FF" + GetParameter(this.args, "LINECOLOR"), //<Color> - Line GetParameter(this.args, "LINESIZEUNITS"), //<Unit> - Line GetParameter(this.args, "LABELSIZEUNITS"), //<Unit> - Polygon Label GetParameter(this.args, "LABELFONTSIZE"), //<SizeX> - Polygon Label Size GetParameter(this.args, "LABELFONTSIZE"), //<SizeY> - Polygon Label Size "FF" + GetParameter(this.args, "LABELFORECOLOR"), //<ForegroundColor> - Polygon Label "FF" + GetParameter(this.args, "LABELBACKCOLOR"), //<BackgroundColor> - Polygon Label GetParameter(this.args, "LABELBACKSTYLE"), //<BackgroundStyle> - Polygon Label bold, //<Bold> - Polygon Label italic, //<Bold> - Polygon Label underline, //<Underlined> - Polygon Label GetParameter(this.args, "FILLPATTERN"), //<FillPattern> - Fill hexFgTransparency + GetParameter(this.args, "FILLFORECOLOR"), //<ForegroundColor> - Fill hexBgTransparency + GetParameter(this.args, "FILLBACKCOLOR"), //<BackgroundColor> - Fill GetParameter(this.args, "BORDERPATTERN"), //<LineStyle> - Fill GetParameter(this.args, "BORDERTHICKNESS"), //<Thickness> - Fill "FF" + GetParameter(this.args, "BORDERCOLOR"), //<Color> - Fill GetParameter(this.args, "BORDERSIZEUNITS"), //<Unit> - Fill HttpContext.Current.Server.HtmlEncode(url)); //<Url> - url link MgByteReader byteReader = new MgByteReader(markupLayerDefinition, "text/xml"); resourceService.SetResource(new MgResourceIdentifier(libraryPath + GetParameter(this.args, "MARKUPNAME") + ".LayerDefinition"), byteReader, null); }
// 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); }
//---------------------------------------------------------------------------------------- // �� �ܣ� ����Ҫ��Դ // // �� �ߣ� // // // �� �ڣ�2007.05.# // //----------------------------------------------------------------------------------------- public void CreateFeatureSource(String sessionId) { MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); // ΪҪ��Դ������ʱҪ���� MgClassDefinition classDefinition = new MgClassDefinition(); classDefinition.SetName("Points"); classDefinition.SetDescription("��ʱҪ���ࣨ�㣩"); classDefinition.SetDefaultGeometryPropertyName("GEOM"); // ����Ҫ�����ʶ���� MgDataPropertyDefinition identityProperty = new MgDataPropertyDefinition("KEY"); identityProperty.SetDataType(MgPropertyType.Int32); identityProperty.SetAutoGeneration(true); identityProperty.SetReadOnly(true); classDefinition.GetIdentityProperties().Add(identityProperty); classDefinition.GetProperties().Add(identityProperty); // ������ͨ���ԣ�NAME) MgDataPropertyDefinition nameProperty = new MgDataPropertyDefinition("NAME"); nameProperty.SetDataType(MgPropertyType.String); classDefinition.GetProperties().Add(nameProperty); // �����������ԣ�GEOM) MgGeometricPropertyDefinition geometryProperty = new MgGeometricPropertyDefinition("GEOM"); geometryProperty.SetGeometryTypes(MgFeatureGeometricType.Point); classDefinition.GetProperties().Add(geometryProperty); // ����Ҫ��ģʽ MgFeatureSchema featureSchema = new MgFeatureSchema("PointSchema", "this is Point schema"); featureSchema.GetClasses().Add(classDefinition); // ����Ҫ��Դ String featureSourceName = "Session:" + sessionId + "//Points.FeatureSource"; MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName); String wkt = "LOCALCS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; MgCreateSdfParams sdfParams = new MgCreateSdfParams("ArbitraryXY", wkt, featureSchema); featureService.CreateFeatureSource(resourceIdentifier, sdfParams); }
//--------------------------------------------------------------------------------------- // // ���ܣ�����һ����Ϊ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 CreateDebugFeatureSource() { var id = new MgDataPropertyDefinition("ID"); //NOXLATE id.DataType = MgPropertyType.Int32; id.Nullable = false; id.SetAutoGeneration(true); var geom = new MgGeometricPropertyDefinition("Geometry"); //NOXLATE geom.GeometryTypes = MgFeatureGeometricType.Point; geom.SpatialContextAssociation = "MapCs"; //NOXLATE var cls = new MgClassDefinition(); cls.Name = "Debug"; //NOXLATE var props = cls.GetProperties(); props.Add(id); props.Add(geom); var idProps = cls.GetIdentityProperties(); idProps.Add(id); cls.DefaultGeometryPropertyName = "Geometry"; //NOXLATE var schema = new MgFeatureSchema("Default", "Default schema"); //NOXLATE var classes = schema.GetClasses(); classes.Add(cls); //We can make anything up here, there's no real concept of sessions var sessionId = Guid.NewGuid().ToString(); var debugFsId = new MgResourceIdentifier("Session:" + sessionId + "//Debug" + Guid.NewGuid().ToString() + ".FeatureSource"); //NOXLATE var createSdf = new MgCreateSdfParams("MapCs", _map.GetMapSRS(), schema); //NOXLATE var featureSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); var resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService); featureSvc.CreateFeatureSource(debugFsId, createSdf); byte[] bytes = Encoding.UTF8.GetBytes(string.Format(Debug.DebugLayer, debugFsId.ToString(), "Default:Debug", "Geometry")); //NOXLATE var source = new MgByteSource(bytes, bytes.Length); var debugLayerId = new MgResourceIdentifier("Session:" + sessionId + "//" + debugFsId.Name + ".LayerDefinition"); //NOXLATE var breader = source.GetReader(); resSvc.SetResource(debugLayerId, breader, null); _debugLayer = new MgdLayer(debugLayerId, resSvc); _debugLayer.SetLegendLabel("Debug Layer"); //NOXLATE _debugLayer.SetVisible(true); _debugLayer.SetDisplayInLegend(true); var mapLayers = _map.GetLayers(); mapLayers.Insert(0, _debugLayer); UpdateCenterDebugPoint(); }
private void btnCreatePointsOfInterest_Click(object sender, EventArgs e) { string layerName = "Points"; string legendLabel = "Points of Interest"; string groupName = "Analysis"; MgMapViewerProvider provider = _viewer.GetProvider(); MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); //We use MgdFeatureService instead of MgFeatureService as this sample demonstrates APIs unique to mg-desktop MgdFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService); MgMapBase map = _viewer.GetMap(); MgLayerCollection layers = map.GetLayers(); MgLayerGroupCollection groups = map.GetLayerGroups(); //NOTE: mg-desktop has no formal concept of a session repository, but we still //support session-based resources as a form of temporary resource (for the duration //of the application). Session ids in mg-desktop can be any arbitrary string string sessionId = Guid.NewGuid().ToString(); if (layers.IndexOf(layerName) >= 0) { MessageBox.Show("Layer (" + layerName + ") already created"); return; } //---------------------------------------------------// // Create a feature source with point data. // (The Sheboygan sample data does not contain such data, // so we"ll create it.) // Create a feature class definition for the new feature source MgClassDefinition classDefinition = new MgClassDefinition(); classDefinition.SetName("Points"); classDefinition.SetDescription("Feature class with point data."); classDefinition.SetDefaultGeometryPropertyName("GEOM"); MgPropertyDefinitionCollection idProps = classDefinition.GetIdentityProperties(); MgPropertyDefinitionCollection clsProps = classDefinition.GetProperties(); // Create an identify property MgDataPropertyDefinition identityProperty = new MgDataPropertyDefinition("KEY"); identityProperty.SetDataType(MgPropertyType.Int32); identityProperty.SetAutoGeneration(true); identityProperty.SetReadOnly(true); // Add the identity property to the class definition clsProps.Add(identityProperty); idProps.Add(identityProperty); // Create a name property MgDataPropertyDefinition nameProperty = new MgDataPropertyDefinition("NAME"); nameProperty.SetDataType(MgPropertyType.String); // Add the name property to the class definition clsProps.Add(nameProperty); // Create a geometry property MgGeometricPropertyDefinition geometryProperty = new MgGeometricPropertyDefinition("GEOM"); geometryProperty.SetGeometryTypes(MgFeatureGeometricType.Point); // Add the geometry property to the class definition clsProps.Add(geometryProperty); // Create a feature schema MgFeatureSchema featureSchema = new MgFeatureSchema("PointSchema", "Point schema"); MgClassDefinitionCollection classes = featureSchema.GetClasses(); // Add the feature schema to the class definition classes.Add(classDefinition); // Create the feature source String featureSourceName = "Library://Samples/DevGuide/Data/points.FeatureSource"; MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName); //wkt = "LOCALCS[\"*XY-MT*\",LOCAL_DATUM[\"*X-Y*\",10000],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; String wkt = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]"; MgCreateSdfParams sdfParams = new MgCreateSdfParams("LatLong", wkt, featureSchema); featureService.CreateFeatureSource(resourceIdentifier, sdfParams); // We need to add some data to the sdf before using it. The spatial context // reader must have an extent. MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection(); MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter(); MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgGeometryFactory geometryFactory = new MgGeometryFactory(); // Make four points batchPropertyCollection.Add(MakePoint("Point A", -87.727, 43.748, wktReaderWriter, agfReaderWriter)); batchPropertyCollection.Add(MakePoint("Point B", -87.728, 43.730, wktReaderWriter, agfReaderWriter)); batchPropertyCollection.Add(MakePoint("Point C", -87.726, 43.750, wktReaderWriter, agfReaderWriter)); batchPropertyCollection.Add(MakePoint("Point D", -87.728, 43.750, wktReaderWriter, agfReaderWriter)); // Old way commented out /* // Add the batch property collection to the feature source MgInsertFeatures cmd = new MgInsertFeatures("Points", batchPropertyCollection); MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection(); featureCommandCollection.Add(cmd); // Execute the "add" commands featureService.UpdateFeatures(resourceIdentifier, featureCommandCollection, false); */ // Here's the mg-desktop way MgPropertyCollection insertResult = featureService.InsertFeatures(resourceIdentifier, "Points", batchPropertyCollection); for (int i = 0; i < insertResult.GetCount(); i++) { MgFeatureProperty fp = insertResult.GetItem(i) as MgFeatureProperty; if (fp != null) { MgFeatureReader fr = fp.GetValue(); fr.Close(); } } // ... //---------------------------------------------------// // Create a new layer LayerDefinitionFactory factory = new LayerDefinitionFactory(); // Create a mark symbol String resourceId = "Library://Samples/Sheboygan/Symbols/BasicSymbols.SymbolLibrary"; String symbolName = "PushPin"; String width = "24"; // unit = points String height = "24"; // unit = points String color = "FFFF0000"; String markSymbol = factory.CreateMarkSymbol(resourceId, symbolName, width, height, color); // Create a text symbol String text = "ID"; String fontHeight = "12"; String foregroundColor = "FF000000"; String textSymbol = factory.CreateTextSymbol(text, fontHeight, foregroundColor); // Create a point rule. String ruleLegendLabel = "trees"; String filter = ""; String pointRule = factory.CreatePointRule(ruleLegendLabel, filter, textSymbol, markSymbol); // Create a point type style. String pointTypeStyle = factory.CreatePointTypeStyle(pointRule); // Create a scale range. String minScale = "0"; String maxScale = "1000000000000"; String pointScaleRange = factory.CreateScaleRange(minScale, maxScale, pointTypeStyle); // Create the layer definiton. String featureName = "PointSchema:Points"; String geometry = "GEOM"; String layerDefinition = factory.CreateLayerDefinition(featureSourceName, featureName, geometry, pointScaleRange); //---------------------------------------------------// // ... XmlDocument domDocument = new XmlDocument(); domDocument.LoadXml(layerDefinition); //Add the layer to the map // TODO: Should probably validate this XML content using (MemoryStream ms = new MemoryStream()) { domDocument.Save(ms); ms.Position = 0L; //Note we do this to ensure our XML content is free of any BOM characters byte[] ldfBytes = ms.ToArray(); Encoding utf8 = Encoding.UTF8; String layerDefStr = new String(utf8.GetChars(ldfBytes)); ldfBytes = new byte[layerDefStr.Length - 1]; int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, ldfBytes, 0); // Save the new layer definition to the session repository MgByteSource byteSource = new MgByteSource(ldfBytes, ldfBytes.Length); MgResourceIdentifier resourceID = new MgResourceIdentifier("Session:" + sessionId + "//" + layerName + ".LayerDefinition"); resourceService.SetResource(resourceID, byteSource.GetReader(), null); //Insert this layer to our map MgdLayer newLayer = new MgdLayer(resourceID, resourceService); newLayer.Name = layerName; newLayer.LegendLabel = legendLabel; newLayer.DisplayInLegend = true; newLayer.SetVisible(true); layers.Insert(0, newLayer); //Create analysis group if not already created if (groups.IndexOf(groupName) < 0) { MgLayerGroup group = new MgLayerGroup(groupName); group.LegendLabel = groupName; group.DisplayInLegend = true; groups.Add(group); newLayer.Group = group; } MessageBox.Show("Layer (" + layerName + ") created"); _viewer.RefreshMap(); IMapLegend legend = Shell.Instance.Legend; if (legend != null) legend.RefreshLegend(); } }
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); }
public void CreateSdfParams() { MgCreateSdfParams csp = new MgCreateSdfParams(); csp.SpatialContextName = "TestSpatialContextName"; Assert.AreEqual("TestSpatialContextName", csp.SpatialContextName); csp.SpatialContextDescription = "TestSpatialContextDescription"; Assert.AreEqual("TestSpatialContextDescription", csp.SpatialContextDescription); csp.CoordinateSystemWkt = "TestCoordSysWkt"; Assert.AreEqual("TestCoordSysWkt", csp.CoordinateSystemWkt); csp.XYTolerance = 0.0001; Assert.AreEqual(0.0001, csp.XYTolerance); csp.ZTolerance = 0.01; Assert.AreEqual(0.01, csp.ZTolerance); MgFeatureSchema schema = new MgFeatureSchema("SchemaName", "SchemaDescription"); csp.FeatureSchema = schema; Assert.AreEqual(schema.Name, csp.FeatureSchema.Name); Assert.AreEqual(schema.Description, csp.FeatureSchema.Description); }
public string AddNaaz(double X, double Y, string MapSession, string mapName) { try { string dataSource = "Session:" + MapSession + "//RedlineSymbol.FeatureSource"; string layerDef = "Session:" + MapSession + "//RedlineSymbol.LayerDefinition"; // MgSiteConnection site = MGMapObject.GetMgSite(MapSession); MgUserInformation userInfo = new MgUserInformation(MapSession); MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); // Create a ReserviceService object and use it to open the Map // object from the sessions repository. Use the Map object to // determine if the "AddressMarker" layer is visible. MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgMap map = new MgMap(); map.Open(resourceService, mapName); // MgLayer locationLayer = GetLayerByName(map, "LocationMarker"); if (siteConnection == null) { return "יש לרענן את האתר , לחיצה על כפתור הבית בפינה השמאלית עליונה"; } MgFeatureService featureSrvc = siteConnection.CreateService(2) as MgFeatureService; MgResourceService resourceSrvc = siteConnection.CreateService(0) as MgResourceService; MgResourceIdentifier dataSourceId = new MgResourceIdentifier(dataSource); MgResourceIdentifier layerDefId = new MgResourceIdentifier(layerDef); //MgMap map = MGMapObject.GetMgMap(resourceSrvc, mapName); MgGeometryFactory geomFactory = new MgGeometryFactory(); MgPoint geom = geomFactory.CreatePoint(geomFactory.CreateCoordinateXY(X, Y)); if (DataSourceExists(resourceSrvc, dataSourceId)) { resourceSrvc.DeleteResource(dataSourceId); } MgClassDefinition classDef = CreateFeatureClass("RedlineSymbol", "RedlineSymbol"); AddFeatureClassProperty(classDef, "KEY", 7, true); SetGeometryProp(classDef); MgFeatureSchema schema = CreateSchema(classDef, "RedlineSymbolShema", "RedlineSymbolShema"); MgCreateSdfParams parameters = new MgCreateSdfParams("ArbitraryXY", GetMapSrs(map), schema); featureSrvc.CreateFeatureSource(dataSourceId, parameters); MgLayerCollection layers = map.GetLayers(); MgLayer layer = FindLayer(layers, layerDef); LayerDefinitionFactory LayerDeffactory = new LayerDefinitionFactory(); if ((layer == null) && LayerDeffactory.CreateLayerDef("SymbolLayerDef_Cell", dataSource, "RedlineSymbol", "")) { resourceSrvc.SetResource(layerDefId, LayerDeffactory.layerDefContent, null); layer = new MgLayer(layerDefId, resourceSrvc); layer.SetDisplayInLegend(false); layer.SetSelectable(false); layer.SetVisible(true); layer.SetLegendLabel("ZoomSymbol"); layers.Insert(0, layer); } MgPropertyCollection featureProps = new MgPropertyCollection(); AddPointFeature("RedlineSymbol", featureProps, geom, featureSrvc, dataSourceId); if (layer != null) { layer.ForceRefresh(); } map.Save(resourceSrvc); siteConnection = null; map = null; dataSourceId = null; layerDefId = null; featureSrvc = null; resourceSrvc = null; geomFactory = null; geom = null; classDef = null; schema = null; featureProps = null; parameters = null; layers = null; layer = null; LayerDeffactory = null; GC.Collect(); GC.WaitForPendingFinalizers(); return "Ok"; } catch (Exception ex) { return ex.Message; } }
private void CheckRedlineLayer() { if (_redlineLayer == null) { MgdMap map = (MgdMap)_viewer.GetMap(); MgMapViewerProvider provider = _viewer.GetProvider(); MgdFeatureService featSvc = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService); MgResourceService resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService); string sessionId = Guid.NewGuid().ToString(); MgResourceIdentifier fsId = new MgResourceIdentifier("Session:" + sessionId + "//Redline.FeatureSource"); MgResourceIdentifier ldfId = new MgResourceIdentifier("Session:" + sessionId + "//Redline.LayerDefinition"); string featureClass = "Default:Redline"; string geometry = "Geometry"; string xml = string.Format(Layers.Redline, fsId.ToString(), featureClass, geometry); //Construct our schema for the redline data store MgFeatureSchema schema = new MgFeatureSchema("Default", "Redline schema"); MgClassDefinition cls = new MgClassDefinition(); cls.Name = "Redline"; MgDataPropertyDefinition id = new MgDataPropertyDefinition("ID"); id.DataType = MgPropertyType.Int32; id.SetAutoGeneration(true); MgGeometricPropertyDefinition geom = new MgGeometricPropertyDefinition(geometry); geom.SpatialContextAssociation = "Default"; geom.GeometryTypes = MgFeatureGeometricType.Curve | MgFeatureGeometricType.Point | MgFeatureGeometricType.Solid | MgFeatureGeometricType.Surface; MgPropertyDefinitionCollection clsProps = cls.GetProperties(); clsProps.Add(id); clsProps.Add(geom); MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties(); idProps.Add(id); cls.DefaultGeometryPropertyName = geometry; MgClassDefinitionCollection classes = schema.GetClasses(); classes.Add(cls); //Create the feature source MgCreateSdfParams create = new MgCreateSdfParams("Default", map.GetMapSRS(), schema); featSvc.CreateFeatureSource(fsId, create); //Then the layer definition byte[] bytes = Encoding.UTF8.GetBytes(xml); MgByteSource source = new MgByteSource(bytes, bytes.Length); resSvc.SetResource(ldfId, source.GetReader(), null); //Now create the runtime layer and add to map _redlineLayer = new MgdLayer(ldfId, resSvc); _redlineLayer.LegendLabel = "Redlining"; _redlineLayer.Name = "Redline"; _redlineLayer.Visible = true; _redlineLayer.Selectable = true; _redlineLayer.DisplayInLegend = true; MgLayerCollection layers = map.GetLayers(); layers.Insert(0, _redlineLayer); } }
private void CreateRedlineLayer() { MgMapBase map = mgMapViewer1.GetMap(); MgdServiceFactory fact = new MgdServiceFactory(); MgdFeatureService featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); MgResourceService resSvc = (MgResourceService)fact.CreateService(MgServiceType.ResourceService); //Note that mg-desktop does not have a concept of sessions like the //official MapGuide API, but it *does* allow session-based resources //as a way of having temporary resources. Such resources will reside //in a special directory for session resources (specified in Platform.ini) // //You can plug whatever string as the session id, but the resource identifier //must satisfy the session id pattern: // // Session:<session id string>//Path/To/Your.ResourceType // //These files are removed with MgPlatform.Terminate(), which is called in this //application as part of the exiting process. string sessionId = Guid.NewGuid().ToString(); MgResourceIdentifier fsId = new MgResourceIdentifier("Session:" + sessionId + "//Redline.FeatureSource"); MgResourceIdentifier ldfId = new MgResourceIdentifier("Session:" + sessionId + "//Redline.LayerDefinition"); //Create our point redline schema. It looks like this: // // Default // Redline // ID (int32, autogenerated) // Geometry (coordinate system same as map string featureClass = "Default:Redline"; string geometry = "Geometry"; MgFeatureSchema schema = new MgFeatureSchema("Default", "Redline schema"); MgClassDefinition cls = new MgClassDefinition(); cls.Name = "Redline"; MgDataPropertyDefinition id = new MgDataPropertyDefinition("ID"); id.DataType = MgPropertyType.Int32; id.SetAutoGeneration(true); MgGeometricPropertyDefinition geom = new MgGeometricPropertyDefinition(geometry); geom.SpatialContextAssociation = "Default"; geom.GeometryTypes = MgFeatureGeometricType.Curve | MgFeatureGeometricType.Point | MgFeatureGeometricType.Solid | MgFeatureGeometricType.Surface; MgPropertyDefinitionCollection clsProps = cls.GetProperties(); clsProps.Add(id); clsProps.Add(geom); MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties(); idProps.Add(id); cls.DefaultGeometryPropertyName = geometry; MgClassDefinitionCollection classes = schema.GetClasses(); classes.Add(cls); //Create the feature source with this schema. We use the map's //coordinate system for the feature source to ensure features //that we create, will line up with the map MgCreateSdfParams create = new MgCreateSdfParams("Default", map.GetMapSRS(), schema); featSvc.CreateFeatureSource(fsId, create); //Then create the layer definition. RedlineLayer.xml contains the template string xml = string.Format(File.ReadAllText("RedlineLayer.xml"), fsId.ToString(), featureClass, geometry); var bytes = Encoding.UTF8.GetBytes(xml); MgByteSource source = new MgByteSource(bytes, bytes.Length); resSvc.SetResource(ldfId, source.GetReader(), null); //Now create the runtime layer and add to map _pointLayer = new MgdLayer(ldfId, resSvc); _pointLayer.LegendLabel = "Redlining"; _pointLayer.Name = "Redline"; _pointLayer.Visible = true; _pointLayer.Selectable = true; _pointLayer.DisplayInLegend = true; var layers = map.GetLayers(); layers.Insert(0, _pointLayer); }
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); }