Example #1
0
        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);
        }
    // 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);
    }
Example #3
0
        public static ClassDefinition ConvertClassDefinition(MgClassDefinition mgClass)
        {
            var cls = new ClassDefinition(mgClass.Name, mgClass.Description);
            //foreach (var prop in mgClass.GetProperties())
            var props  = mgClass.GetProperties();
            int pcount = props.GetCount();

            for (int i = 0; i < pcount; i++)
            {
                var prop = props.GetItem(i);
                switch (prop.PropertyType)
                {
                case MgFeaturePropertyType.DataProperty:
                    MgDataPropertyDefinition mgData = (MgDataPropertyDefinition)prop;
                    var dp = ConvertDataProperty(mgData);

                    //API Bug? passing object reference gives incorrect result for identity
                    //properties
                    bool identity = (mgClass.GetIdentityProperties().Contains(prop.Name));
                    cls.AddProperty(dp, identity);
                    break;

                case MgFeaturePropertyType.GeometricProperty:
                    MgGeometricPropertyDefinition mgGeom = (MgGeometricPropertyDefinition)prop;
                    var geom = ConvertGeometricProperty(mgGeom);

                    cls.AddProperty(geom);
                    break;

                case MgFeaturePropertyType.RasterProperty:
                    MgRasterPropertyDefinition mgRaster = (MgRasterPropertyDefinition)prop;
                    var raster = ConvertRasterProperty(mgRaster);

                    cls.AddProperty(raster);
                    break;

                case MgFeaturePropertyType.ObjectProperty:
                    break;

                case MgFeaturePropertyType.AssociationProperty:
                    break;
                }
            }

            cls.DefaultGeometryPropertyName = mgClass.DefaultGeometryPropertyName;

            return(cls);
        }
Example #4
0
 public static void AddFeatureClassProperty(MgClassDefinition classDef, string name, int itype, bool isKey)
 {
     MgDataPropertyDefinition prop = new MgDataPropertyDefinition(name);
     prop.SetDataType(itype);
     if (isKey)
     {
         prop.SetAutoGeneration(true);
         classDef.GetIdentityProperties().Add(prop);
         prop.SetReadOnly(true);
     }
     else
     {
         prop.Nullable = true;
     }
     classDef.GetProperties().Add(prop);
 }
Example #5
0
        public static ClassDefinition ConvertClassDefinition(MgClassDefinition mgClass)
        {
            var cls = new ClassDefinition(mgClass.Name, mgClass.Description);
            //foreach (var prop in mgClass.GetProperties())
            var props = mgClass.GetProperties();
            int pcount = props.GetCount();
            for (int i = 0; i < pcount; i++)
            {
                var prop = props.GetItem(i);
                if (prop.PropertyType == MgFeaturePropertyType.DataProperty)
                {
                    MgDataPropertyDefinition mgData = (MgDataPropertyDefinition)prop;
                    var dp = ConvertDataProperty(mgData);

                    //API Bug? passing object reference gives incorrect result for identity
                    //properties
                    bool identity = (mgClass.GetIdentityProperties().Contains(prop.Name));
                    cls.AddProperty(dp, identity);
                }
                else if (prop.PropertyType == MgFeaturePropertyType.GeometricProperty)
                {
                    MgGeometricPropertyDefinition mgGeom = (MgGeometricPropertyDefinition)prop;
                    var geom = ConvertGeometricProperty(mgGeom);

                    cls.AddProperty(geom);
                }
                else if (prop.PropertyType == MgFeaturePropertyType.RasterProperty)
                {
                    MgRasterPropertyDefinition mgRaster = (MgRasterPropertyDefinition)prop;
                    var raster = ConvertRasterProperty(mgRaster);

                    cls.AddProperty(raster);
                }
                else if (prop.PropertyType == MgFeaturePropertyType.ObjectProperty)
                {

                }
                else if (prop.PropertyType == MgFeaturePropertyType.AssociationProperty)
                {
                }
            }

            cls.DefaultGeometryPropertyName = mgClass.DefaultGeometryPropertyName;

            return cls;
        }
Example #6
0
        public static MgClassDefinition CreateMarkupClass()
        {
            MgClassDefinition markupClass = new MgClassDefinition();
            markupClass.SetName("Markup");
            MgPropertyDefinitionCollection properties = markupClass.GetProperties();
            MgDataPropertyDefinition idProperty = MarkupSchemaFactory.CreateIDProperty();
            properties.Add(idProperty);
            properties.Add(MarkupSchemaFactory.CreateIntProperty("UID", true));
            properties.Add(MarkupSchemaFactory.CreateTextProperty(255));
            properties.Add(MarkupSchemaFactory.CreateReverseTextProperty(255));
            properties.Add(MarkupSchemaFactory.CreateIntProperty("ProjectId", false)); //Need for ProjectManager.
            properties.Add(MarkupSchemaFactory.CreateGeometryProperty(MgFeatureGeometricType.Point | MgFeatureGeometricType.Curve | MgFeatureGeometricType.Surface));

            markupClass.GetIdentityProperties().Add(idProperty);
            markupClass.SetDefaultGeometryPropertyName("Geometry");

            return markupClass;
        }
Example #7
0
        internal void UpdateRedlineText(string text, int[] ids)
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            //HACK: Workaround FeatId leaky abstraction in SHP provider
            MgClassDefinition cls = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            List <string> filters = new List <string>();

            foreach (int id in ids)
            {
                filters.Add(idProp.Name + " = " + id);
            }
            string updateFilter = string.Join(" OR ", filters.ToArray());
            MgFeatureCommandCollection commands     = new MgFeatureCommandCollection();
            MgPropertyCollection       updateValues = new MgPropertyCollection();
            MgStringProperty           updateProp   = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);

            updateValues.Add(updateProp);

            MgUpdateFeatures update = new MgUpdateFeatures(redlineLayer.FeatureClassName, updateValues, updateFilter);

            commands.Add(update);

            MgPropertyCollection result       = redlineLayer.UpdateFeatures(commands);
            MgInt32Property      updateResult = result.GetItem(0) as MgInt32Property;
            MgStringProperty     errorResult  = result.GetItem(0) as MgStringProperty;

            if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
            _viewer.RefreshMap();
        }
Example #8
0
        public static MgClassDefinition CreateClass(int geomType)
        {
            MgClassDefinition cls = new MgClassDefinition();
            cls.SetName(CLASS_NAME);
            MgPropertyDefinitionCollection props = cls.GetProperties();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();

            MgDataPropertyDefinition id = CreateIDProperty();
            MgDataPropertyDefinition text = CreateTextProperty(255);
            MgGeometricPropertyDefinition geom = CreateGeometryProperty(geomType);

            props.Add(id);
            props.Add(text);
            props.Add(geom);

            idProps.Add(id);
            cls.SetDefaultGeometryPropertyName(GEOM_NAME);

            return cls;
        }
Example #9
0
        public static MgClassDefinition CreateClass(int geomType)
        {
            MgClassDefinition cls = new MgClassDefinition();

            cls.SetName(CLASS_NAME);
            MgPropertyDefinitionCollection props   = cls.GetProperties();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();

            MgDataPropertyDefinition      id   = CreateIDProperty();
            MgDataPropertyDefinition      text = CreateTextProperty(255);
            MgGeometricPropertyDefinition geom = CreateGeometryProperty(geomType);

            props.Add(id);
            props.Add(text);
            props.Add(geom);

            idProps.Add(id);
            cls.SetDefaultGeometryPropertyName(GEOM_NAME);

            return(cls);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        public void LoadResults(MgLayerBase layer, MgFeatureQueryOptions query)
        {
            MgClassDefinition clsDef = layer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = clsDef.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps[0];
            string idPropName = idProp.Name;
            string geomName   = layer.FeatureGeometryName;

            MgFeatureReader   reader = layer.SelectFeatures(query);
            MgAgfReaderWriter agfRw  = new MgAgfReaderWriter();

            try
            {
                while (reader.ReadNext())
                {
                    var res = new ParcelFeatureModel();
                    res.ID      = reader.GetInt32(idPropName);
                    res.Owner   = reader.IsNull("RNAME") ? "(unknown)" : reader.GetString("RNAME");
                    res.Address = reader.IsNull("RPROPAD") ? "(unknown)" : reader.GetString("RPROPAD");
                    if (!reader.IsNull(geomName))
                    {
                        MgByteReader agf    = reader.GetGeometry(geomName);
                        MgGeometry   geom   = agfRw.Read(agf);
                        MgPoint      center = geom.Centroid;
                        MgCoordinate coord  = center.Coordinate;

                        res.X = coord.X;
                        res.Y = coord.Y;
                    }
                    this.Results.Add(res);
                }
            }
            finally
            {
                reader.Close();
            }
        }
Example #13
0
        public IEnumerable <RedlineObject> GetAllFeatures()
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            MgResourceIdentifier resId  = new MgResourceIdentifier(redlineLayer.GetFeatureSourceId());
            MgFeatureReader      reader = null;

            try
            {
                reader = _featSvc.SelectFeatures(resId, RedlineSchemaFactory.CLASS_NAME, null);

                //HACK: Another leaky abstraction. SHP will always choose FeatId, so once again
                //use the class definition to determine the identity property name
                MgClassDefinition cls = reader.GetClassDefinition();
                MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                MgPropertyDefinition           keyProp = idProps.GetItem(0);
                string idName = keyProp.GetName();

                while (reader.ReadNext())
                {
                    int    id   = reader.GetInt32(idName);
                    string text = reader.IsNull(RedlineSchemaFactory.TEXT_NAME) ? string.Empty : reader.GetString(RedlineSchemaFactory.TEXT_NAME);

                    yield return(new RedlineObject(id, text));
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Example #14
0
        internal void DeleteRedlines(int[] ids)
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            //HACK: Workaround FeatId leaky abstraction in SHP provider
            MgClassDefinition cls = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            List <string> filters = new List <string>();

            foreach (int id in ids)
            {
                filters.Add(idProp.Name + " = " + id);
            }
            string deleteFilter = string.Join(" OR ", filters.ToArray());
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();

            MgDeleteFeatures delete = new MgDeleteFeatures(redlineLayer.FeatureClassName, deleteFilter);

            commands.Add(delete);

            MgPropertyCollection result       = redlineLayer.UpdateFeatures(commands);
            MgInt32Property      deleteResult = result.GetItem(0) as MgInt32Property;

            if (deleteResult != null && deleteResult.GetValue() > 0)
            {
                _viewer.RefreshMap();
            }
        }
Example #15
0
        internal static MgFeatureSchema ConvertSchema(FeatureSchema source)
        {
            MgFeatureSchema             fs      = new MgFeatureSchema(source.Name, source.Description);
            MgClassDefinitionCollection classes = fs.GetClasses();

            foreach (ClassDefinition cls in source.Classes)
            {
                MgClassDefinition clsDef = new MgClassDefinition();
                clsDef.SetName(cls.Name);
                clsDef.SetDescription(cls.Description);
                clsDef.SetDefaultGeometryPropertyName(cls.DefaultGeometryPropertyName);
                var clsProps = clsDef.GetProperties();
                var idProps  = clsDef.GetIdentityProperties();

                foreach (PropertyDefinition prop in cls.Properties)
                {
                    switch (prop.Type)
                    {
                    case PropertyDefinitionType.Data:
                    {
                        var dp    = new MgDataPropertyDefinition(prop.Name);
                        var srcDp = (DataPropertyDefinition)prop;
                        dp.SetAutoGeneration(srcDp.IsAutoGenerated);
                        dp.SetDataType((int)srcDp.DataType);
                        if (srcDp.DefaultValue != null)
                        {
                            dp.SetDefaultValue(srcDp.DefaultValue);
                        }
                        if (srcDp.Description != null)
                        {
                            dp.SetDescription(srcDp.Description);
                        }
                        dp.SetLength(srcDp.Length);
                        dp.SetNullable(srcDp.IsNullable);
                        dp.SetPrecision(srcDp.Precision);
                        dp.SetReadOnly(srcDp.IsReadOnly);
                        dp.SetScale(srcDp.Scale);

                        clsProps.Add(dp);

                        if (cls.IdentityProperties.Contains(srcDp))
                        {
                            idProps.Add(dp);
                        }
                    }
                    break;

                    case PropertyDefinitionType.Geometry:
                    {
                        var gp    = new MgGeometricPropertyDefinition(prop.Name);
                        var srcGp = (GeometricPropertyDefinition)prop;
                        if (srcGp.Description != null)
                        {
                            gp.SetDescription(srcGp.Description);
                        }
                        gp.SetGeometryTypes((int)srcGp.GeometricTypes);
                        gp.SetHasElevation(srcGp.HasElevation);
                        gp.SetHasMeasure(srcGp.HasMeasure);
                        gp.SetReadOnly(srcGp.IsReadOnly);
                        if (srcGp.SpatialContextAssociation != null)
                        {
                            gp.SetSpatialContextAssociation(srcGp.SpatialContextAssociation);
                        }

                        clsProps.Add(gp);
                    }
                    break;

                    case PropertyDefinitionType.Raster:
                    {
                        var rp    = new MgRasterPropertyDefinition(prop.Name);
                        var srcRp = (RasterPropertyDefinition)prop;
                        rp.SetDefaultImageXSize(srcRp.DefaultImageYSize);
                        rp.SetDefaultImageYSize(srcRp.DefaultImageYSize);
                        if (srcRp.Description != null)
                        {
                            rp.SetDescription(srcRp.Description);
                        }
                        rp.SetNullable(srcRp.IsNullable);
                        rp.SetReadOnly(srcRp.IsReadOnly);
                        if (srcRp.SpatialContextAssociation != null)
                        {
                            rp.SetSpatialContextAssociation(srcRp.SpatialContextAssociation);
                        }

                        clsProps.Add(rp);
                    }
                    break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                classes.Add(clsDef);
            }

            return(fs);
        }
Example #16
0
    private MgFeatureSchema CreateFilterSchema()
    {
        MgFeatureSchema filterSchema = new MgFeatureSchema();
        filterSchema.SetName("FilterSchema");

        MgClassDefinition filterClass = new MgClassDefinition();
        filterClass.SetName("Filter");
        MgPropertyDefinitionCollection properties = filterClass.GetProperties();

        MgDataPropertyDefinition idProperty = new MgDataPropertyDefinition("ID");
        idProperty.SetDataType(MgPropertyType.Int32);
        idProperty.SetReadOnly(true);
        idProperty.SetNullable(false);
        idProperty.SetAutoGeneration(true);
        properties.Add(idProperty);

        MgGeometricPropertyDefinition geometryProperty = new MgGeometricPropertyDefinition("Geometry");
        geometryProperty.SetGeometryTypes(MgFeatureGeometricType.Surface);
        geometryProperty.SetHasElevation(false);
        geometryProperty.SetHasMeasure(true);
        geometryProperty.SetReadOnly(false);
        geometryProperty.SetSpatialContextAssociation("MAPCS");
        properties.Add(geometryProperty);

        filterClass.GetIdentityProperties().Add(idProperty);
        filterClass.SetDefaultGeometryPropertyName("Geometry");

        filterSchema.GetClasses().Add(filterClass);

        return filterSchema;
    }
Example #17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string sessionId = GetRequestParameters(Request)["SESSION"];
            string mapName   = GetRequestParameters(Request)["MAPNAME"];
            string locale    = GetRequestParameters(Request)["LOCALE"];

            if (string.IsNullOrEmpty(sessionId))
            {
                Response.Clear();
                Response.End();
                return;
            }

            if (string.IsNullOrEmpty(mapName))
            {
                Response.Clear();
                Response.End();
                return;
            }

            MgResourceService resourceSrvc = GetMgResurceService(sessionId);
            MgFeatureService  featureSrvc  = GetMgFeatureService(sessionId);

            MgMap map = new MgMap();
            map.Open(resourceSrvc, mapName);

            string layernames = GetRequestParameters(Request)["LAYERNAMES"];
            string GEOMETRY   = GetRequestParameters(Request)["GEOMETRY"];
            string selVar     = GetRequestParameters(Request)["SELECTIONVARIANT"];
            string type       = GetRequestParameters(Request)["tp"];
            string inputSel   = GetRequestParameters(Request)["SELECTION"];

            bool hasInputGeom = false;
            if (!string.IsNullOrEmpty(GEOMETRY))
            {
                hasInputGeom = true;
            }

            //selection ima prednost pred podano geometrijo ...
            MgWktReaderWriter wktrw = new MgWktReaderWriter();
            if (!string.IsNullOrEmpty(inputSel))
            {
                MgGeometry inputGeom = MultiGeometryFromSelection(featureSrvc, map, inputSel);
                GEOMETRY = wktrw.Write(inputGeom);
            }

            MgAgfReaderWriter agfRW = new MgAgfReaderWriter();

            int nLayer = 0;
            // pobrišem in zgradim na novo samo tiste, ki imajo zadetke ...
            int           nSloj  = 0;
            string        filter = "";
            StringBuilder sbOut  = new StringBuilder();
            sbOut.Append("<table width=\"100%\" class=\"results\">");
            sbOut.Append("<tr><td class='header'></td><td class='header'>" + "Layer" + "</td><td class='header' align=\"center\">" + "Select" + "</td><td class='header' align=\"center\">" + "Report" + "</td></tr>");

            MgSelection selAll = new MgSelection(map);

            foreach (MgLayer layer in map.GetLayers())
            {
                if (type != "2")
                {
                    if (!layer.IsVisible())
                    {
                        goto nextlay;
                    }
                }

                if (layer.LegendLabel == "")
                {
                    goto nextlay;
                }

                try
                {
                    nLayer++;

                    filter = String.Format("{0} {1} GeomFromText('{2}')", layer.GetFeatureGeometryName(), selVar, GEOMETRY);

                    //preveriti še filter na Layerju. Ker ne gre drugače, je potrebno pogledati v XML
                    MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
                    MgByteReader         byteReader    = resourceSrvc.GetResourceContent(layerDefResId);

                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    String xmlLayerDef         = byteReader.ToString();
                    doc.LoadXml(xmlLayerDef);

                    KALI.MGE.Objects.KALILayerDefinition.LayerDefinition ld = KALI.MGE.Objects.KALILayerDefinition.LayerDefinition.Parse(xmlLayerDef);

                    if (!string.IsNullOrEmpty(ld.VectorLayerDefinition.Filter))
                    {
                        filter += " AND (" + ld.VectorLayerDefinition.Filter + ")";
                    }

                    //query the features
                    MgFeatureQueryOptions opts = new MgFeatureQueryOptions();
                    opts.SetFilter(filter);
                    String featureClassName    = layer.GetFeatureClassName();
                    MgResourceIdentifier srcId = new MgResourceIdentifier(layer.GetFeatureSourceId());

                    MgFeatureReader features = featureSrvc.SelectFeatures(srcId, featureClassName, opts);

                    bool hasResult = features.ReadNext();

                    if (hasResult)
                    {
                        nSloj++;

                        int n = 0;

                        MgClassDefinition classDef = features.GetClassDefinition();

                        MgPropertyDefinitionCollection classDefProps = classDef.GetIdentityProperties();
                        ArrayList idPropNames = new ArrayList(classDefProps.GetCount());
                        for (int j = 0; j < classDefProps.GetCount(); j++)
                        {
                            MgPropertyDefinition idProp = classDefProps.GetItem(j);
                            idPropNames.Add(idProp.GetName());
                        }

                        MgSelection sel = new MgSelection(map);
                        do
                        {
                            // Generate XML to selection this feature
                            MgPropertyCollection idProps = new MgPropertyCollection();
                            foreach (string id in idPropNames)
                            {
                                int idPropType = features.GetPropertyType(id);
                                switch (idPropType)
                                {
                                case MgPropertyType.Int32:
                                    idProps.Add(new MgInt32Property(id, features.GetInt32(id)));
                                    break;

                                case MgPropertyType.String:
                                    idProps.Add(new MgStringProperty(id, features.GetString(id)));
                                    break;

                                case MgPropertyType.Int64:
                                    idProps.Add(new MgInt64Property(id, features.GetInt64(id)));
                                    break;

                                case MgPropertyType.Double:
                                    idProps.Add(new MgDoubleProperty(id, features.GetDouble(id)));
                                    break;

                                case MgPropertyType.Single:
                                    idProps.Add(new MgSingleProperty(id, features.GetSingle(id)));
                                    break;

                                case MgPropertyType.DateTime:
                                    idProps.Add(new MgDateTimeProperty(id, features.GetDateTime(id)));
                                    break;

                                default:
                                    //throw new SearchError(String.Format(MgLocalizer.GetString("SEARCHTYYPENOTSUP", locale), new Object[] { idPropType.ToString() }), searchError);
                                    break;
                                }
                            }

                            sel.AddFeatureIds(layer, featureClassName, idProps);
                            selAll.AddFeatureIds(layer, featureClassName, idProps);

                            n++;

                            //if (n > 1000) break;
                        } while (features.ReadNext());

                        features.Close();
                        features.Dispose();

                        string selText = EscapeForHtml(sel.ToXml());
                        string seljs   = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/></div>";
                        string seljs3  = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/></div>";

                        string linfo = "<b>" + layer.LegendLabel + "</b><br />" + n.ToString() + " " + "Hits";
                        sbOut.Append("<tr><td class=\"results\">" + nSloj.ToString() + "</td><td class=\"results\">" + linfo + "</td><td align=\"center\" class=\"results\">" + seljs + "</td><td align=\"center\" class=\"results\">" + seljs3 + "</td></tr>");
                    }
                }
                catch (Exception)
                {
                    continue;
                }

nextlay:
                continue;
            }

            sbOut.Append("</table>");

            string selAllText = EscapeForHtml(selAll.ToXml());
            string seljsAll   = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/>" + "Select All" + "</div>";
            string seljsAll3  = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/>" + "Report All" + "</div>";

            sbOut.Append(string.Format("<br /><table width=\"100%\" class=\"results\"><tr><td class=\"results\">{0}</td><td class=\"results\">{1}</td></tr></table>", seljsAll, seljsAll3));


            featureSrvc.Dispose();
            resourceSrvc.Dispose();

            if (nSloj > 0)
            {
                litPrebodi.Text = sbOut.ToString();
            }
            else
            {
                litPrebodiTitle.Visible = false;
                litPrebodi.Text         = "<b>" + "None layer lies below the selected item/area!" + "</b>";
            }

            MgGeometry inGeom = wktrw.Read(GEOMETRY);

            double rw = map.ViewScale / Math.Sqrt(inGeom.Area);

            //koordinate
            if (hasInputGeom & rw > 400)
            {
                string output = "";

                output = pointTransformAndWriteZ(GEOMETRY, map);

                litKoordinate.Text      = output;
                litKoordinateTitle.Text = "Coordinates of selected points:";
            }
        }
    }
Example #18
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            btnCreate.Enabled = false;
            try
            {
                var layerName = txtBufferLayer.Text.Trim();
                if (string.IsNullOrEmpty(layerName))
                {
                    MessageBox.Show(Strings.MsgEnterNameForLayer);
                    return;
                }

                if (lstLayers.SelectedItems.Count == 0)
                {
                    MessageBox.Show(Strings.MsgIncludeLayersToBuffer);
                    return;
                }

                var map      = _viewer.GetMap();
                var layers   = map.GetLayers();
                var provider = _viewer.GetProvider();

                //From here, it's the same logic as buffer.aspx in .net MapGuide AJAX viewer
                MgResourceIdentifier fsId  = new MgResourceIdentifier("Session:" + _sessionId + "//" + txtBufferLayer.Text + "_Buffer.FeatureSource");   //NOXLATE
                MgResourceIdentifier ldfId = new MgResourceIdentifier("Session:" + _sessionId + "//" + txtBufferLayer.Text + "_Buffer.LayerDefinition"); //NOXLATE

                MgLayerBase layer      = Util.FindLayer(layers, txtBufferLayer.Text);
                string[]    layerNames = GetLayerNames();

                double          distance = Convert.ToDouble(numBufferDistance.Value);
                MeasurementUnit bUnits   = (MeasurementUnit)cmbUnits.SelectedItem;
                switch (bUnits)
                {
                case MeasurementUnit.Feet:
                    distance *= 0.30480;
                    break;

                case MeasurementUnit.Kilometers:
                    distance *= 1000;
                    break;

                case MeasurementUnit.Miles:
                    distance *= 1609.35;
                    break;
                }

                String             srsDefMap   = Util.GetMapSrs(map);
                MgCoordinateSystem srsMap      = provider.GetMapCoordinateSystem();
                string             mapSrsUnits = "";
                bool arbitraryMapSrs           = (srsMap.GetType() == MgCoordinateSystemType.Arbitrary);
                if (arbitraryMapSrs)
                {
                    mapSrsUnits = srsMap.GetUnits();
                }

                String xtrans     = String.Format("{0:x2}", ((int)(255 * Convert.ToInt32(numFillTransparency.Value) / 100))); //NOXLATE
                var    lineColor  = Util.ToHtmlColor(pnlBorderColor.BackColor);
                var    foreColor  = Util.ToHtmlColor(pnlFillColor.BackColor);
                var    backColor  = Util.ToHtmlColor(pnlFillBackColor.BackColor);
                String layerTempl = string.Format(Properties.Resources.AreaLayerDef,
                                                  fsId.ToString(),
                                                  "BufferSchema:Buffer", //NOXLATE
                                                  "GEOM",                //NOXLATE
                                                  cmbFillPattern.SelectedItem,
                                                  xtrans + foreColor,
                                                  ((0 != 1 /*transparent*/) ? "ff" : "00") + backColor, //NOXLATE
                                                  cmbBorderPattern.SelectedItem,
                                                  numLineThickness.Value.ToString(NumberFormatInfo.InvariantInfo),
                                                  lineColor
                                                  );
                byte[]       bytes           = Encoding.UTF8.GetBytes(layerTempl);
                MgByteSource src             = new MgByteSource(bytes, bytes.Length);
                MgByteReader layerDefContent = src.GetReader();
                _resSvc.SetResource(ldfId, layerDefContent, null);

                bool newBuffer = false;
                if (layer == null)
                {
                    newBuffer = true;

                    //Targetting a new layer. create a data source for it
                    //
                    MgClassDefinition classDef = new MgClassDefinition();

                    classDef.SetName("Buffer");                                //NOXLATE
                    classDef.SetDescription("Feature class for buffer layer"); //NOXLATE
                    classDef.SetDefaultGeometryPropertyName("GEOM");           //NOXLATE

                    //Set KEY property
                    MgDataPropertyDefinition prop = new MgDataPropertyDefinition("KEY"); //NOXLATE
                    prop.SetDataType(MgPropertyType.Int32);
                    prop.SetAutoGeneration(true);
                    prop.SetReadOnly(true);
                    classDef.GetIdentityProperties().Add(prop);
                    classDef.GetProperties().Add(prop);

                    //Set ID property. Hold this segment ID
                    prop = new MgDataPropertyDefinition("ID"); //NOXLATE
                    prop.SetDataType(MgPropertyType.Int32);
                    classDef.GetProperties().Add(prop);

                    //Set geometry property
                    MgGeometricPropertyDefinition geomProp = new MgGeometricPropertyDefinition("GEOM"); //NOXLATE
                    //prop.SetGeometryTypes(MgFeatureGeometricType.mfgtSurface); //TODO use the constant when exposed
                    geomProp.SetGeometryTypes(4);
                    classDef.GetProperties().Add(geomProp);

                    //Create the schema
                    MgFeatureSchema schema = new MgFeatureSchema("BufferSchema", "Temporary buffer schema"); //NOXLATE
                    schema.GetClasses().Add(classDef);

                    //finally, creation of the feature source
                    MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "LatLong", map.GetMapSRS(), schema); //NOXLATE
                    _featSvc.CreateFeatureSource(fsId, sdfParams);

                    //Add layer to map
                    layer = provider.CreateLayer(ldfId);
                    layer.SetName(txtBufferLayer.Text);
                    layer.SetLegendLabel(txtBufferLayer.Text);
                    layer.SetDisplayInLegend(true);
                    layer.SetSelectable(true);
                    layers.Insert(0, layer);
                }
                else
                {
                    //data source already exist. clear its content
                    //
                    Util.ClearDataSource(_featSvc, fsId, "BufferSchema:Buffer"); //NOXLATE
                }

                var sel       = _viewer.GetSelection();
                var selLayers = sel.GetLayers();

                MgAgfReaderWriter    agfRW            = new MgAgfReaderWriter();
                MgGeometryCollection bufferGeometries = new MgGeometryCollection();
                MgGeometry           geomBuffer;

                MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
                int featId = 0;

                MgBatchPropertyCollection propCollection = new MgBatchPropertyCollection();

                int excludedLayers                   = 0;
                MgCoordinateSystem   srsDs           = null;
                MgGeometryCollection inputGeometries = new MgGeometryCollection();

                int bufferFeatures = 0;
                for (int li = 0; li < selLayers.GetCount(); li++)
                {
                    MgLayerBase selLayer     = selLayers.GetItem(li);
                    bool        inputLayer   = false;
                    String      selLayerName = selLayer.GetName();
                    for (int il = 0; il < layerNames.Length; il++)
                    {
                        if (layerNames[il].Equals(selLayerName))
                        {
                            inputLayer = true;
                            break;
                        }
                    }
                    if (inputLayer == false)
                    {
                        continue;
                    }

                    // get the data source SRS
                    //
                    MgResourceIdentifier   featSourceId = new MgResourceIdentifier(selLayer.GetFeatureSourceId());
                    MgSpatialContextReader ctxs         = _featSvc.GetSpatialContexts(featSourceId, false);
                    String srsDefDs = string.Empty;
                    if (ctxs != null && ctxs.ReadNext())
                    {
                        srsDefDs = ctxs.GetCoordinateSystemWkt();
                    }

                    if (srsDefDs == null || srsDefDs.Length == 0)
                    {
                        excludedLayers++;
                        continue;
                    }

                    var srsFactory = new MgCoordinateSystemFactory();
                    srsDs = srsFactory.Create(srsDefDs);
                    bool   arbitraryDsSrs = (srsDs.GetType() == MgCoordinateSystemType.Arbitrary);
                    String dsSrsUnits     = string.Empty;

                    if (arbitraryDsSrs)
                    {
                        dsSrsUnits = srsDs.GetUnits();
                    }

                    // exclude layer if:
                    //  the map is non-arbitrary and the layer is arbitrary or vice-versa
                    //     or
                    //  layer and map are both arbitrary but have different units
                    //
                    if ((arbitraryDsSrs != arbitraryMapSrs) || (arbitraryDsSrs && (dsSrsUnits != mapSrsUnits)))
                    {
                        excludedLayers++;
                        continue;
                    }

                    // calculate distance in the data source SRS units
                    //
                    double dist = srsDs.ConvertMetersToCoordinateSystemUnits(distance);

                    // calculate great circle unless data source srs is arbitrary
                    MgCoordinateSystemMeasure measure;
                    if (!arbitraryDsSrs)
                    {
                        measure = srsDs.GetMeasure();
                    }
                    else
                    {
                        measure = null;
                    }

                    // create a SRS transformer if necessary
                    MgCoordinateSystemTransform srsXform;
                    if (!srsDefDs.Equals(srsDefMap))
                    {
                        srsXform = srsFactory.GetTransform(srsDs, srsMap);
                    }
                    else
                    {
                        srsXform = null;
                    }

                    String featureClassName = selLayer.GetFeatureClassName();
                    String filter           = sel.GenerateFilter(selLayer, featureClassName);
                    if (filter == null || filter.Length == 0)
                    {
                        continue;
                    }

                    MgFeatureQueryOptions query = new MgFeatureQueryOptions();
                    query.SetFilter(filter);

                    MgResourceIdentifier featureSource = new MgResourceIdentifier(selLayer.GetFeatureSourceId());

                    MgFeatureReader features = _featSvc.SelectFeatures(featureSource, featureClassName, query);

                    if (features.ReadNext())
                    {
                        MgClassDefinition classDef     = features.GetClassDefinition();
                        String            geomPropName = classDef.GetDefaultGeometryPropertyName();

                        do
                        {
                            MgByteReader geomReader = features.GetGeometry(geomPropName);
                            MgGeometry   geom       = agfRW.Read(geomReader);

                            if (!chkMergeBuffers.Checked)
                            {
                                geomBuffer = geom.Buffer(dist, measure);
                                if (geomBuffer != null)
                                {
                                    if (srsXform != null)
                                    {
                                        geomBuffer = (MgGeometry)geomBuffer.Transform(srsXform);
                                    }
                                    Util.AddFeatureToCollection(propCollection, agfRW, featId++, geomBuffer);
                                    bufferFeatures++;
                                }
                            }
                            else
                            {
                                if (srsXform != null)
                                {
                                    geom = (MgGeometry)geom.Transform(srsXform);
                                }
                                inputGeometries.Add(geom);
                            }
                        }while (features.ReadNext());

                        features.Close();
                    }
                }

                if (chkMergeBuffers.Checked)
                {
                    if (inputGeometries.GetCount() > 0)
                    {
                        double dist = srsMap.ConvertMetersToCoordinateSystemUnits(distance);
                        MgCoordinateSystemMeasure measure;
                        if (!arbitraryMapSrs)
                        {
                            measure = srsMap.GetMeasure();
                        }
                        else
                        {
                            measure = null;
                        }

                        MgGeometryFactory geomFactory = new MgGeometryFactory();
                        geomBuffer = geomFactory.CreateMultiGeometry(inputGeometries).Buffer(dist, measure);
                        if (geomBuffer != null)
                        {
                            Util.AddFeatureToCollection(propCollection, agfRW, featId, geomBuffer);
                            bufferFeatures = 1;
                        }
                    }
                }

                if (propCollection.GetCount() > 0)
                {
                    commands.Add(new MgInsertFeatures("BufferSchema:Buffer", propCollection)); //NOXLATE

                    //Insert the features in the temporary data source
                    //
                    Util.ReleaseReader(_featSvc.UpdateFeatures(fsId, commands, false), commands);
                }

                // Save the new map state
                //
                layer.ForceRefresh();
                _viewer.RefreshMap();

                //build report message
                if (newBuffer)
                {
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerCreated, txtBufferLayer.Text));
                }
                else
                {
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerUpdated, txtBufferLayer.Text));
                }
            }
            finally
            {
                btnCreate.Enabled = true;
            }
        }
Example #19
0
        private void Ensure()
        {
            if (_registryFsId == null)
            {
                _registryFsId = new MgResourceIdentifier("Session:" + _sessionID + "//MarkupRegistry.FeatureSource");

                if (!_resSvc.ResourceExists(_registryFsId))
                {
                    //Markup Registry Feature Source Schema
                    //
                    //Default
                    //  MarkupRegistry
                    //    ResourceId (String, Identity, Not Null)
                    //    LayerDefintion (String, Not Null)
                    //    Name (String, Not Null)
                    //    FdoProvider (String, Not Null)
                    //    GeometryTypes (Int, Not Null)
                    MgFeatureSchema schema = new MgFeatureSchema("Default", "");
                    MgClassDefinition cls = new MgClassDefinition();
                    cls.SetName("MarkupRegistry");

                    MgDataPropertyDefinition regId = new MgDataPropertyDefinition("ResourceId");
                    regId.SetDataType(MgPropertyType.String);
                    regId.SetLength(1024);
                    regId.SetNullable(false);

                    MgDataPropertyDefinition layerDefId = new MgDataPropertyDefinition("LayerDefinition");
                    layerDefId.SetDataType(MgPropertyType.String);
                    layerDefId.SetLength(1024);
                    layerDefId.SetNullable(false);

                    MgDataPropertyDefinition name = new MgDataPropertyDefinition("Name");
                    name.SetDataType(MgPropertyType.String);
                    name.SetLength(512);
                    name.SetNullable(false);

                    MgDataPropertyDefinition provider = new MgDataPropertyDefinition("FdoProvider");
                    provider.SetDataType(MgPropertyType.String);
                    provider.SetLength(512);
                    provider.SetNullable(false);

                    MgDataPropertyDefinition geomTypes = new MgDataPropertyDefinition("GeometryTypes");
                    geomTypes.SetDataType(MgPropertyType.Int32);
                    geomTypes.SetNullable(false);

                    MgDataPropertyDefinition styleType = new MgDataPropertyDefinition("StyleType");
                    styleType.SetDataType(MgPropertyType.Int32);
                    styleType.SetNullable(false);

                    MgPropertyDefinitionCollection dataProps = cls.GetProperties();
                    dataProps.Add(regId);
                    dataProps.Add(layerDefId);
                    dataProps.Add(name);
                    dataProps.Add(provider);
                    dataProps.Add(geomTypes);
                    dataProps.Add(styleType);

                    MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                    idProps.Add(regId);

                    MgClassDefinitionCollection classes = schema.GetClasses();
                    classes.Add(cls);

                    //No coordinate system required here because we're not storing spatial data
                    MgFileFeatureSourceParams createSdf = new MgFileFeatureSourceParams("OSGeo.SDF", "Default", "", schema);
                    _featSvc.CreateFeatureSource(_registryFsId, createSdf);
                }
            }
        }
Example #20
0
        private void InsertRedlineGeometry(string text, MgGeometry geom, RedlineAction onRedlineAdded)
        {
            MgPropertyCollection feature  = new MgPropertyCollection();
            MgByteReader         agf      = _agfRW.Write(geom);
            MgGeometryProperty   geomProp = new MgGeometryProperty(RedlineSchemaFactory.GEOM_NAME, agf);

            feature.Add(geomProp);
            MgStringProperty strProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);

            feature.Add(strProp);

            MgMapBase         map                  = _viewer.GetMap();
            MgLayerCollection layers               = map.GetLayers();
            MgLayerBase       redlineLayer         = layers.GetItem(_layer.SystemName);
            MgClassDefinition cls                  = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();

            MgInsertFeatures insert = new MgInsertFeatures(redlineLayer.FeatureClassName, feature);

            commands.Add(insert);

            MgPropertyCollection result = redlineLayer.UpdateFeatures(commands);
            //Insert result is a MgFeatureProperty containing an MgFeatureReader
            MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty;
            MgStringProperty  errorResult  = result.GetItem(0) as MgStringProperty;

            if (insertResult != null)
            {
                var reader   = insertResult.GetValue();
                int inserted = 0;
                int?id       = null;
                try
                {
                    if (reader.ReadNext())
                    {
                        inserted++;
                        id = reader.GetInt32(idProp.Name);
                    }
                }
                catch (MgException ex)
                {
                    ex.Dispose();
                }
                finally
                {
                    reader.Close();
                }
                if (inserted > 0)
                {
                    _viewer.RefreshMap();
                    onRedlineAdded(id, text);
                }
            }
            else if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
        }
Example #21
0
        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]]";
            MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "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
            MgFeatureReader insertResult = featureService.InsertFeatures(resourceIdentifier, "Points", batchPropertyCollection);

            insertResult.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();
                }
            }
        }
Example #22
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ����Ҫ��Դ
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�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);
    }
Example #23
0
        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();
            }
        }
Example #24
0
        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);
        }
Example #25
0
        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);
        }
Example #26
0
        private void Ensure()
        {
            if (_registryFsId == null)
            {
                _registryFsId = new MgResourceIdentifier("Session:" + _sessionID + "//MarkupRegistry.FeatureSource");

                if (!_resSvc.ResourceExists(_registryFsId))
                {
                    //Markup Registry Feature Source Schema
                    //
                    //Default
                    //  MarkupRegistry
                    //    ResourceId (String, Identity, Not Null)
                    //    LayerDefintion (String, Not Null)
                    //    Name (String, Not Null)
                    //    FdoProvider (String, Not Null)
                    //    GeometryTypes (Int, Not Null)
                    MgFeatureSchema   schema = new MgFeatureSchema("Default", "");
                    MgClassDefinition cls    = new MgClassDefinition();
                    cls.SetName("MarkupRegistry");

                    MgDataPropertyDefinition regId = new MgDataPropertyDefinition("ResourceId");
                    regId.SetDataType(MgPropertyType.String);
                    regId.SetLength(1024);
                    regId.SetNullable(false);

                    MgDataPropertyDefinition layerDefId = new MgDataPropertyDefinition("LayerDefinition");
                    layerDefId.SetDataType(MgPropertyType.String);
                    layerDefId.SetLength(1024);
                    layerDefId.SetNullable(false);

                    MgDataPropertyDefinition name = new MgDataPropertyDefinition("Name");
                    name.SetDataType(MgPropertyType.String);
                    name.SetLength(512);
                    name.SetNullable(false);

                    MgDataPropertyDefinition provider = new MgDataPropertyDefinition("FdoProvider");
                    provider.SetDataType(MgPropertyType.String);
                    provider.SetLength(512);
                    provider.SetNullable(false);

                    MgDataPropertyDefinition geomTypes = new MgDataPropertyDefinition("GeometryTypes");
                    geomTypes.SetDataType(MgPropertyType.Int32);
                    geomTypes.SetNullable(false);

                    MgDataPropertyDefinition styleType = new MgDataPropertyDefinition("StyleType");
                    styleType.SetDataType(MgPropertyType.Int32);
                    styleType.SetNullable(false);

                    MgPropertyDefinitionCollection dataProps = cls.GetProperties();
                    dataProps.Add(regId);
                    dataProps.Add(layerDefId);
                    dataProps.Add(name);
                    dataProps.Add(provider);
                    dataProps.Add(geomTypes);
                    dataProps.Add(styleType);

                    MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                    idProps.Add(regId);

                    MgClassDefinitionCollection classes = schema.GetClasses();
                    classes.Add(cls);

                    //No coordinate system required here because we're not storing spatial data
                    MgFileFeatureSourceParams createSdf = new MgFileFeatureSourceParams("OSGeo.SDF", "Default", "", schema);
                    _featSvc.CreateFeatureSource(_registryFsId, createSdf);
                }
            }
        }
Example #27
0
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����һ����Ϊ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);
        //
    }
Example #28
0
        private static MgClassDefinition CreateFieldsOrderClass()
        {
            MgClassDefinition classDef = new MgClassDefinition {
            Name = "FIELDS_ORDER"
            };

            MgPropertyDefinitionCollection propCollection = classDef.GetProperties();
            MgPropertyDefinition propIdDef = HtzSdfHelper.CreateIdProperty("ID");
            propCollection.Add(propIdDef);
            classDef.GetIdentityProperties().Add(propIdDef);
            propCollection.Add(HtzSdfHelper.CreateIntProperty("ORDER_ID"));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("FEAT_CLASS_NAME", 0x19));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("PROPERTY_NAME", 0x19));
            return classDef;
        }
Example #29
0
        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);
            }
        }
Example #30
0
        private static MgClassDefinition CreateMaintenanceClass(bool isLog)
        {
            MgClassDefinition classDef = new MgClassDefinition {
            Name = isLog ? "MaintenanceLog" : "Maintenance"
            };

            MgPropertyDefinitionCollection propCollection = classDef.GetProperties();
            MgPropertyDefinition propIdDef = HtzSdfHelper.CreateIdProperty();
            propCollection.Add(propIdDef);
            classDef.GetIdentityProperties().Add(propIdDef);
            if (isLog)
            {
            propCollection.Add(HtzSdfHelper.CreateIntProperty("ItemId"));
            }
            else
            {
            propCollection.Add(HtzSdfHelper.CreateTextProperty("FeatureSource", 0xff));
            propCollection.Add(HtzSdfHelper.CreateIntProperty("UID"));
            }
            propCollection.Add(HtzSdfHelper.CreateTextProperty("InfrastructureType", 50));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("OperationType", 50));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("OperationDescription", 0xff));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("Status", 50));
            propCollection.Add(HtzSdfHelper.CreateDateTimeProperty("dtStart"));
            propCollection.Add(HtzSdfHelper.CreateDateTimeProperty("dtDue"));
            propCollection.Add(HtzSdfHelper.CreateDateTimeProperty("dtEnd"));
            propCollection.Add(HtzSdfHelper.CreateDateTimeProperty("dtUpdate"));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("Contractor", 50));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("Inspector", 50));
            propCollection.Add(HtzSdfHelper.CreateIntProperty("WorkCost"));
            propCollection.Add(HtzSdfHelper.CreateIntProperty("OrderNum"));
            propCollection.Add(HtzSdfHelper.CreateTextProperty("Note", 0xff));
            if (!isLog)
            {
            propCollection.Add(HtzSdfHelper.CreateGeometricProperty("Main"));
            classDef.DefaultGeometryPropertyName = "Geometry";
            }
            return classDef;
        }
Example #31
0
        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);
        }
Example #32
0
        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
            MgFileFeatureSourceParams create = new MgFileFeatureSourceParams("OSGeo.SDF", "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);
        }
Example #33
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            btnCreate.Enabled = false;
            try
            {
                var layerName = txtBufferLayer.Text.Trim();
                if (string.IsNullOrEmpty(layerName))
                {
                    MessageBox.Show(Strings.MsgEnterNameForLayer);
                    return;
                }

                if (lstLayers.SelectedItems.Count == 0)
                {
                    MessageBox.Show(Strings.MsgIncludeLayersToBuffer);
                    return;
                }

                var map = _viewer.GetMap();
                var layers = map.GetLayers();
                var provider = _viewer.GetProvider();

                //From here, it's the same logic as buffer.aspx in .net MapGuide AJAX viewer
                MgResourceIdentifier fsId = new MgResourceIdentifier("Session:" + _sessionId + "//" + txtBufferLayer.Text + "_Buffer.FeatureSource"); //NOXLATE
                MgResourceIdentifier ldfId = new MgResourceIdentifier("Session:" + _sessionId + "//" + txtBufferLayer.Text + "_Buffer.LayerDefinition"); //NOXLATE

                MgLayerBase layer = Util.FindLayer(layers, txtBufferLayer.Text);
                string[] layerNames = GetLayerNames();

                double distance = Convert.ToDouble(numBufferDistance.Value);
                MeasurementUnit bUnits = (MeasurementUnit)cmbUnits.SelectedItem;
                switch (bUnits)
                {
                    case MeasurementUnit.Feet:
                        distance *= 0.30480;
                        break;
                    case MeasurementUnit.Kilometers:
                        distance *= 1000;
                        break;
                    case MeasurementUnit.Miles:
                        distance *= 1609.35;
                        break;
                }

                String srsDefMap = Util.GetMapSrs(map);
                MgCoordinateSystem srsMap = provider.GetMapCoordinateSystem();
                string mapSrsUnits = "";
                bool arbitraryMapSrs = (srsMap.GetType() == MgCoordinateSystemType.Arbitrary);
                if (arbitraryMapSrs)
                    mapSrsUnits = srsMap.GetUnits();

                String xtrans = String.Format("{0:x2}", ((int)(255 * Convert.ToInt32(numFillTransparency.Value) / 100))); //NOXLATE
                var lineColor = Util.ToHtmlColor(pnlBorderColor.BackColor);
                var foreColor = Util.ToHtmlColor(pnlFillColor.BackColor);
                var backColor = Util.ToHtmlColor(pnlFillBackColor.BackColor);
                String layerTempl = string.Format(Properties.Resources.AreaLayerDef,
                        fsId.ToString(),
                        "BufferSchema:Buffer", //NOXLATE
                        "GEOM", //NOXLATE
                        cmbFillPattern.SelectedItem,
                        xtrans + foreColor,
                        ((0 != 1/*transparent*/) ? "ff" : "00") + backColor, //NOXLATE
                        cmbBorderPattern.SelectedItem,
                        numLineThickness.Value.ToString(NumberFormatInfo.InvariantInfo),
                        lineColor
                );
                byte[] bytes = Encoding.UTF8.GetBytes(layerTempl);
                MgByteSource src = new MgByteSource(bytes, bytes.Length);
                MgByteReader layerDefContent = src.GetReader();
                _resSvc.SetResource(ldfId, layerDefContent, null);

                bool newBuffer = false;
                if (layer == null)
                {
                    newBuffer = true;

                    //Targetting a new layer. create a data source for it
                    //
                    MgClassDefinition classDef = new MgClassDefinition();

                    classDef.SetName("Buffer"); //NOXLATE
                    classDef.SetDescription("Feature class for buffer layer"); //NOXLATE
                    classDef.SetDefaultGeometryPropertyName("GEOM"); //NOXLATE

                    //Set KEY property
                    MgDataPropertyDefinition prop = new MgDataPropertyDefinition("KEY"); //NOXLATE
                    prop.SetDataType(MgPropertyType.Int32);
                    prop.SetAutoGeneration(true);
                    prop.SetReadOnly(true);
                    classDef.GetIdentityProperties().Add(prop);
                    classDef.GetProperties().Add(prop);

                    //Set ID property. Hold this segment ID
                    prop = new MgDataPropertyDefinition("ID"); //NOXLATE
                    prop.SetDataType(MgPropertyType.Int32);
                    classDef.GetProperties().Add(prop);

                    //Set geometry property
                    MgGeometricPropertyDefinition geomProp = new MgGeometricPropertyDefinition("GEOM"); //NOXLATE
                    //prop.SetGeometryTypes(MgFeatureGeometricType.mfgtSurface); //TODO use the constant when exposed
                    geomProp.SetGeometryTypes(4);
                    classDef.GetProperties().Add(geomProp);

                    //Create the schema
                    MgFeatureSchema schema = new MgFeatureSchema("BufferSchema", "Temporary buffer schema"); //NOXLATE
                    schema.GetClasses().Add(classDef);

                    //finally, creation of the feature source
                    MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "LatLong", map.GetMapSRS(), schema); //NOXLATE
                    _featSvc.CreateFeatureSource(fsId, sdfParams);

                    //Add layer to map
                    layer = provider.CreateLayer(ldfId);
                    layer.SetName(txtBufferLayer.Text);
                    layer.SetLegendLabel(txtBufferLayer.Text);
                    layer.SetDisplayInLegend(true);
                    layer.SetSelectable(true);
                    layers.Insert(0, layer);
                }
                else
                {
                    //data source already exist. clear its content
                    //
                    Util.ClearDataSource(_featSvc, fsId, "BufferSchema:Buffer"); //NOXLATE
                }

                var sel = _viewer.GetSelection();
                var selLayers = sel.GetLayers();

                MgAgfReaderWriter agfRW = new MgAgfReaderWriter();
                MgGeometryCollection bufferGeometries = new MgGeometryCollection();
                MgGeometry geomBuffer;

                MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
                int featId = 0;

                MgBatchPropertyCollection propCollection = new MgBatchPropertyCollection();

                int excludedLayers = 0;
                MgCoordinateSystem srsDs = null;
                MgGeometryCollection inputGeometries = new MgGeometryCollection();

                int bufferFeatures = 0;
                for (int li = 0; li < selLayers.GetCount(); li++)
                {
                    MgLayerBase selLayer = selLayers.GetItem(li);
                    bool inputLayer = false;
                    String selLayerName = selLayer.GetName();
                    for (int il = 0; il < layerNames.Length; il++)
                    {
                        if (layerNames[il].Equals(selLayerName))
                        {
                            inputLayer = true;
                            break;
                        }
                    }
                    if (inputLayer == false)
                    {
                        continue;
                    }

                    // get the data source SRS
                    //
                    MgResourceIdentifier featSourceId = new MgResourceIdentifier(selLayer.GetFeatureSourceId());
                    MgSpatialContextReader ctxs = _featSvc.GetSpatialContexts(featSourceId, false);
                    String srsDefDs = string.Empty;
                    if (ctxs != null && ctxs.ReadNext())
                        srsDefDs = ctxs.GetCoordinateSystemWkt();

                    if (srsDefDs == null || srsDefDs.Length == 0)
                    {
                        excludedLayers++;
                        continue;
                    }

                    var srsFactory = new MgCoordinateSystemFactory();
                    srsDs = srsFactory.Create(srsDefDs);
                    bool arbitraryDsSrs = (srsDs.GetType() == MgCoordinateSystemType.Arbitrary);
                    String dsSrsUnits = string.Empty;

                    if (arbitraryDsSrs)
                        dsSrsUnits = srsDs.GetUnits();

                    // exclude layer if:
                    //  the map is non-arbitrary and the layer is arbitrary or vice-versa
                    //     or
                    //  layer and map are both arbitrary but have different units
                    //
                    if ((arbitraryDsSrs != arbitraryMapSrs) || (arbitraryDsSrs && (dsSrsUnits != mapSrsUnits)))
                    {
                        excludedLayers++;
                        continue;
                    }

                    // calculate distance in the data source SRS units
                    //
                    double dist = srsDs.ConvertMetersToCoordinateSystemUnits(distance);

                    // calculate great circle unless data source srs is arbitrary
                    MgCoordinateSystemMeasure measure;
                    if (!arbitraryDsSrs)
                        measure = srsDs.GetMeasure();
                    else
                        measure = null;

                    // create a SRS transformer if necessary
                    MgCoordinateSystemTransform srsXform;
                    if (!srsDefDs.Equals(srsDefMap))
                        srsXform = srsFactory.GetTransform(srsDs, srsMap);
                    else
                        srsXform = null;

                    String featureClassName = selLayer.GetFeatureClassName();
                    String filter = sel.GenerateFilter(selLayer, featureClassName);
                    if (filter == null || filter.Length == 0)
                        continue;

                    MgFeatureQueryOptions query = new MgFeatureQueryOptions();
                    query.SetFilter(filter);

                    MgResourceIdentifier featureSource = new MgResourceIdentifier(selLayer.GetFeatureSourceId());

                    MgFeatureReader features = _featSvc.SelectFeatures(featureSource, featureClassName, query);

                    if (features.ReadNext())
                    {
                        MgClassDefinition classDef = features.GetClassDefinition();
                        String geomPropName = classDef.GetDefaultGeometryPropertyName();

                        do
                        {
                            MgByteReader geomReader = features.GetGeometry(geomPropName);
                            MgGeometry geom = agfRW.Read(geomReader);

                            if (!chkMergeBuffers.Checked)
                            {
                                geomBuffer = geom.Buffer(dist, measure);
                                if (geomBuffer != null)
                                {
                                    if (srsXform != null)
                                        geomBuffer = (MgGeometry)geomBuffer.Transform(srsXform);
                                    Util.AddFeatureToCollection(propCollection, agfRW, featId++, geomBuffer);
                                    bufferFeatures++;
                                }
                            }
                            else
                            {
                                if (srsXform != null)
                                    geom = (MgGeometry)geom.Transform(srsXform);
                                inputGeometries.Add(geom);
                            }
                        }
                        while (features.ReadNext());

                        features.Close();
                    }
                }

                if (chkMergeBuffers.Checked)
                {
                    if (inputGeometries.GetCount() > 0)
                    {
                        double dist = srsMap.ConvertMetersToCoordinateSystemUnits(distance);
                        MgCoordinateSystemMeasure measure;
                        if (!arbitraryMapSrs)
                            measure = srsMap.GetMeasure();
                        else
                            measure = null;

                        MgGeometryFactory geomFactory = new MgGeometryFactory();
                        geomBuffer = geomFactory.CreateMultiGeometry(inputGeometries).Buffer(dist, measure);
                        if (geomBuffer != null)
                        {
                            Util.AddFeatureToCollection(propCollection, agfRW, featId, geomBuffer);
                            bufferFeatures = 1;
                        }
                    }
                }

                if (propCollection.GetCount() > 0)
                {
                    commands.Add(new MgInsertFeatures("BufferSchema:Buffer", propCollection)); //NOXLATE

                    //Insert the features in the temporary data source
                    //
                    Util.ReleaseReader(_featSvc.UpdateFeatures(fsId, commands, false), commands);
                }

                // Save the new map state
                //
                layer.ForceRefresh();
                _viewer.RefreshMap();

                //build report message
                if (newBuffer)
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerCreated, txtBufferLayer.Text));
                else
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerUpdated, txtBufferLayer.Text));
            }
            finally
            {
                btnCreate.Enabled = true;
            }
        }
Example #34
0
        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
                MgFileFeatureSourceParams create = new MgFileFeatureSourceParams("OSGeo.SDF", "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);
            }
        }
Example #35
0
        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();
        }