コード例 #1
0
ファイル: CollectionTests.cs プロジェクト: achilex/MgDev
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgPropertyCollection propVals = new MgPropertyCollection();
            MgInt32Property      prop     = new MgInt32Property("prop", 1);

            propVals.Add(prop);
            MgUpdateFeatures update = new MgUpdateFeatures("class2", propVals, "where cat < dog");
            MgInsertFeatures insert = new MgInsertFeatures("class3", propVals);
            MgDeleteFeatures del    = new MgDeleteFeatures("class1", "where cat > dog");

            MgFeatureCommandCollection coll = new MgFeatureCommandCollection();

            coll.Add(update);
            coll.Add(insert);
            coll.Add(del);

            Assert.AreEqual(3, coll.Count);
            Assert.AreEqual(MgFeatureCommandType.DeleteFeatures, coll[2].GetCommandType());
            coll[0] = coll[1];

            string txt = "";

            foreach (MgFeatureCommand cmd in coll)
            {
                txt += "[" + cmd.GetCommandType() + "]";
            }
            Assert.AreEqual("[0][0][2]", txt);
        }
コード例 #2
0
ファイル: Util.cs プロジェクト: achilex/MgDev
        public static void ReleaseReader(MgPropertyCollection res, MgFeatureCommandCollection commands)
        {
            if (res == null)
            {
                return;
            }

            for (int i = 0; i < res.GetCount(); i++)
            {
                MgFeatureCommand cmd = commands.GetItem(i);
                if (cmd is MgInsertFeatures)
                {
                    MgFeatureProperty resProp = res.GetItem(i) as MgFeatureProperty;
                    if (resProp != null)
                    {
                        MgFeatureReader reader = resProp.GetValue() as MgFeatureReader;
                        if (reader == null)
                        {
                            return;
                        }
                        reader.Close();
                    }
                }
            }
        }
コード例 #3
0
    public bool ClearSpatialFilter()
    {
        bool result = true;
        MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);

        MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource");

        MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;
        MgFeatureService featureService = siteConnection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
        MgMap map = new MgMap();
        map.Open(resourceService, Request["MAPNAME"]);

        MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

        MgLayer layer = null;
        MgLayerCollection layers = map.GetLayers();
        if (layers.Contains("_QuerySpatialFilter"))
        {
            layer = (MgLayer)layers.GetItem("_QuerySpatialFilter");
            updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0"));
            featureService.UpdateFeatures(sdfResId, updateCommands, false);
            layers.Remove(layer);
            map.Save(resourceService);
        }

        return result;
    }
コード例 #4
0
        internal void DeleteLayer(RedlineLayer layer)
        {
            var regId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgDeleteFeatures           delete   = new MgDeleteFeatures("Default:MarkupRegistry", "ResourceId = '" + layer.FeatureSource + "'");

            commands.Add(delete);

            MgPropertyCollection results      = _featSvc.UpdateFeatures(regId, commands, false);
            MgInt32Property      deleteResult = results.GetItem(0) as MgInt32Property;

            if (deleteResult != null && deleteResult.GetValue() > 0)
            {
                var ldfId = new MgResourceIdentifier(layer.LayerDefinition);
                var fsId  = new MgResourceIdentifier(layer.FeatureSource);

                if (_resSvc.ResourceExists(ldfId))
                {
                    _resSvc.DeleteResource(ldfId);
                }

                if (_resSvc.ResourceExists(fsId))
                {
                    _resSvc.DeleteResource(fsId);
                }
            }
        }
コード例 #5
0
        internal void AddRedlineLayer(RedlineLayer layer, string fdoProvider)
        {
            var fsId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands   = new MgFeatureCommandCollection();
            MgPropertyCollection       insertVals = new MgPropertyCollection();

            MgStringProperty regId     = new MgStringProperty("ResourceId", layer.FeatureSource);
            MgStringProperty ldfId     = new MgStringProperty("LayerDefinition", layer.LayerDefinition);
            MgStringProperty name      = new MgStringProperty("Name", layer.Name);
            MgStringProperty provider  = new MgStringProperty("FdoProvider", fdoProvider);
            MgInt32Property  geomTypes = new MgInt32Property("GeometryTypes", layer.GeometryTypes);
            MgInt32Property  styleType = new MgInt32Property("StyleType", (int)layer.StyleType);

            insertVals.Add(regId);
            insertVals.Add(ldfId);
            insertVals.Add(name);
            insertVals.Add(provider);
            insertVals.Add(geomTypes);
            insertVals.Add(styleType);

            MgInsertFeatures insert = new MgInsertFeatures("Default:MarkupRegistry", insertVals);

            commands.Add(insert);

            MgPropertyCollection result       = _featSvc.UpdateFeatures(fsId, commands, false);
            MgFeatureProperty    insertResult = result.GetItem(0) as MgFeatureProperty;

            if (insertResult != null)
            {
                MgFeatureReader fr = insertResult.GetValue();
                fr.Close();
            }
        }
コード例 #6
0
ファイル: Util.cs プロジェクト: achilex/MgDev
        public static void ClearDataSource(MgFeatureService featSvc, MgResourceIdentifier fsId, String featureName)
        {
            MgDeleteFeatures           deleteCmd = new MgDeleteFeatures(featureName, "ID >= 0"); //NOXLATE
            MgFeatureCommandCollection commands  = new MgFeatureCommandCollection();

            commands.Add(deleteCmd);
            featSvc.UpdateFeatures(fsId, commands, false);
        }
コード例 #7
0
ファイル: GService.asmx.cs プロジェクト: ranyaof/Meuhedet
 public static void AddPointFeature(string FeatureName, MgPropertyCollection featureProps, MgPoint geom, MgFeatureService featureSrvc, MgResourceIdentifier dataSourceId)
 {
     MgByteReader geomReader = new MgAgfReaderWriter().Write(geom);
     MgGeometryProperty geometryProp = new MgGeometryProperty("GEOM", geomReader);
     featureProps.Add(geometryProp);
     MgInsertFeatures cmd = new MgInsertFeatures(FeatureName, featureProps);
     MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
     commands.Add(cmd);
     ReleaseReader(featureSrvc.UpdateFeatures(dataSourceId, commands, false));
 }
コード例 #8
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();
        }
コード例 #9
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();
            }
        }
コード例 #10
0
ファイル: RedlineEditor.cs プロジェクト: kanbang/Colt
        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();
            }
        }
コード例 #11
0
ファイル: RedlineEditor.cs プロジェクト: kanbang/Colt
        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();
        }
コード例 #12
0
ファイル: RedlineEditor.cs プロジェクト: kanbang/Colt
        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());
            }
        }
コード例 #13
0
ファイル: MgBufferControlImpl.cs プロジェクト: achilex/MgDev
        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;
            }
        }
コード例 #14
0
ファイル: RedlineRegistry.cs プロジェクト: kanbang/Colt
        internal void AddRedlineLayer(RedlineLayer layer, string fdoProvider)
        {
            var fsId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgPropertyCollection insertVals = new MgPropertyCollection();

            MgStringProperty regId = new MgStringProperty("ResourceId", layer.FeatureSource);
            MgStringProperty ldfId = new MgStringProperty("LayerDefinition", layer.LayerDefinition);
            MgStringProperty name = new MgStringProperty("Name", layer.Name);
            MgStringProperty provider = new MgStringProperty("FdoProvider", fdoProvider);
            MgInt32Property geomTypes = new MgInt32Property("GeometryTypes", layer.GeometryTypes);
            MgInt32Property styleType = new MgInt32Property("StyleType", (int)layer.StyleType);

            insertVals.Add(regId);
            insertVals.Add(ldfId);
            insertVals.Add(name);
            insertVals.Add(provider);
            insertVals.Add(geomTypes);
            insertVals.Add(styleType);

            MgInsertFeatures insert = new MgInsertFeatures("Default:MarkupRegistry", insertVals);
            commands.Add(insert);

            MgPropertyCollection result = _featSvc.UpdateFeatures(fsId, commands, false);
            MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty;
            if (insertResult != null)
            {
                MgFeatureReader fr = insertResult.GetValue();
                fr.Close();
            }
        }
コード例 #15
0
ファイル: CollectionTest.cs プロジェクト: kanbang/Colt
        public void FeatureCommandCollection()
        {
            MgPropertyCollection propVals = new MgPropertyCollection();
            MgInt32Property prop = new MgInt32Property("prop", 1);
            propVals.Add(prop);
            MgUpdateFeatures update = new MgUpdateFeatures("class2", propVals, "where cat < dog");
            MgInsertFeatures insert = new MgInsertFeatures("class3", propVals);
            MgDeleteFeatures del = new MgDeleteFeatures("class1", "where cat > dog");

            MgFeatureCommandCollection coll = new MgFeatureCommandCollection();
            coll.Add(update);
            coll.Add(insert);
            coll.Add(del);

            Assert.AreEqual(3, coll.Count);
            Assert.AreEqual(MgFeatureCommandType.DeleteFeatures, coll[2].GetCommandType());
            coll[0] = coll[1];

            string txt = "";
            foreach (MgFeatureCommand cmd in coll)
            {
                txt += "[" + cmd.GetCommandType() + "]";
            }
            Assert.AreEqual("[0][0][2]", txt);
        }
コード例 #16
0
ファイル: MgBufferControlImpl.cs プロジェクト: kanbang/Colt
        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;
            }
        }
コード例 #17
0
 public void CreateNew(int uid, string infrastructureType)
 {
     if (!string.IsNullOrEmpty(infrastructureType) && (infrastructureType != "בחר מרשימה"))
     {
         SetInfrastructureType(this._parentLayer.FeatureSourceId, infrastructureType);
         MgGeometryProperty geometry = null;
         MgResourceIdentifier resId = new MgResourceIdentifier(this._parentLayer.FeatureSourceId);
         MgFeatureQueryOptions opt = new MgFeatureQueryOptions();
         opt.SetFilter(string.Format("{0}={1}", this._uidKey, uid));
         MgFeatureReader reader = this._helper.FeatureService.SelectFeatures(resId, this._parentLayer.FeatureClassName, opt);
         MgClassDefinition classDefinition = this._helper.FeatureService.GetClassDefinition(resId, this._parentLayer.FeatureClassName.Split(new char[] { ':' })[0], this._parentLayer.FeatureClassName.Split(new char[] { ':' })[1]);
         if (classDefinition != null)
         {
             string geomName = classDefinition.DefaultGeometryPropertyName;
             if (reader.ReadNext())
             {
                 MgByteReader value = reader.GetGeometry(geomName);
                 if (value != null)
                 {
                     geometry = new MgGeometryProperty(geomName, value);
                 }
             }
         }
         reader.Close();
         reader.Dispose();
         if (geometry != null)
         {
             MgDateTime today = new MgDateTime();
             MgPropertyCollection properties = new MgPropertyCollection {
             geometry,
             new MgInt32Property("UID", uid),
             new MgStringProperty("InfrastructureType", infrastructureType),
             new MgStringProperty("OperationType", "לא מוגדר"),
             new MgStringProperty("Status", "פתוח"),
             new MgStringProperty("FeatureSource", this._parentLayer.FeatureSourceId),
             new MgDateTimeProperty("dtStart", today),
             new MgDateTimeProperty("dtDue", today),
             new MgDateTimeProperty("dtUpdate", today)
         };
             MgInsertFeatures insert = new MgInsertFeatures("Maintenance", properties);
             MgFeatureCommandCollection commands = new MgFeatureCommandCollection {
             insert
         };
             this._helper.FeatureService.UpdateFeatures(this._sdfResId, commands, false);
         }
     }
 }
コード例 #18
0
 private void SetOrder()
 {
     int index = 1;
     MgFeatureCommandCollection cmdCollection = new MgFeatureCommandCollection();
     MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection {
     CreateOrderEntry("FeatureSource", 0),
     CreateOrderEntry("UID", 0),
     CreateOrderEntry("InfrastructureType", index++),
     CreateOrderEntry("OperationType", index++),
     CreateOrderEntry("OperationDescription", index++),
     CreateOrderEntry("Status", index++),
     CreateOrderEntry("Contractor", index++),
     CreateOrderEntry("Inspector", index++),
     CreateOrderEntry("OrderNum", index++),
     CreateOrderEntry("dtStart", index++),
     CreateOrderEntry("dtDue", index++),
     CreateOrderEntry("dtEnd", index++),
     CreateOrderEntry("dtUpdate", index++),
     CreateOrderEntry("WorkCost", index++),
     CreateOrderEntry("Note", index)
     };
     MgInsertFeatures insert = new MgInsertFeatures("Maintenance:FIELDS_ORDER", batchPropertyCollection);
     cmdCollection.Add(insert);
     this._helper.FeatureService.UpdateFeatures(this._sdfResId, cmdCollection, false);
 }
コード例 #19
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����Ҫ�ض���
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    public void createNewParcel(MgPolygon geom, ParcelProperty newParcel)
    {
        MgPropertyCollection properties = buildPropertyCol(newParcel);
        MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();
        MgByteReader byteReader = agfWriter.Write(geom);
        properties.Add(new MgGeometryProperty("SHPGEOM", byteReader));

        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        MgResourceIdentifier parcelSource = new MgResourceIdentifier("Library://MgTutorial/Data/Parcels.FeatureSource");

        MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
        commands.Add(new MgInsertFeatures("Parcels", properties));
        featureService.UpdateFeatures(parcelSource, commands, false);

        //////////////////////////////////////////
        /*
        MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
        MgPropertyCollection properties = new MgPropertyCollection();
        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
        MgByteReader   byteReader = agfReaderWriter.Write(geometry);
        MgGeometryProperty geometryProperty = new MgGeometryProperty("SHPGEOM",byteReader);
        properties.Add(new MgInt32Property("RSQFT", 322));
        properties.Add(new MgStringProperty("RNAME", "YourName"));
        properties.Add(new MgStringProperty("RTYPE", "GFC"));

        MgPropertyCollection properties = new MgPropertyCollection ();
        properties.Add(geometryProperty);
        MgInsertFeatures insertCommand = new MgInsertFeatures(className, properties);
        commands.Add(insertCommand);
        featureService.UpdateFeatures(featureSource, commands, false);
         * */
    }
コード例 #20
0
        /* OldUpdateFeature
        public void oldUpdateFeature(string filter)
        {
            string featureclassname = string.empty;

            mgresourceidentifier featureresid = new mgresourceidentifier(mlayer.getfeaturesourceid());

            mgbytereader reader1 = msiteutilities.resourceservice.getresourceheader(featureresid);
            string s = reader1.tostring();
            //join update
            mgstringcollection r = msiteutilities.featureservice.getclasses(featureresid, mlayer.featureclassname.split(':')[0]);
            if (r.getcount() > 1)
            {
                mgclassdefinition classdefinition = msiteutilities.featureservice.getclassdefinition(featureresid, mlayer.featureclassname.split(':')[0], mlayer.featureclassname.split(':')[1]);
                dictionary<string, list<mgpropertydefinition>> propcollection = new dictionary<string, list<mgpropertydefinition>>();
                foreach(var item in classdefinition.getproperties())
                {
                    string[] strs = item.qualifiedname.split('.');
                    if(!propcollection.containskey(strs[0]))
                    {
                        propcollection.add(strs[0], new list<mgpropertydefinition>());
                    }
                    propcollection[strs[0]].add(item);
                }
                string joinedschema = r.getitem(1);
                string[] arr = joinedschema.split(']');
                string schemaname = arr[2];
                string prefix = arr[1].remove(0, 1);
                string joinname = arr[0].remove(0, 1);
                featureclassname = r.getitem(0);
                dictionary<string, featproperty> parentproperties = new dictionary<string, featproperty>();
                dictionary<string, featproperty> childproperties = new dictionary<string, featproperty>();
                foreach (var item in propertiescollection)
                {
                    if (item.key.indexof(prefix) >= 0)
                    {
                        item.value.name = item.value.name.substring(prefix.length);
                        childproperties.add(item.value.name, item.value);
                    }
                    else
                    {
                        parentproperties.add(item.key, item.value);
                    }
                }

                updatingfeature(featureresid, featureclassname, filter, parentproperties);

                if (propertiescollection.containskey("uid"))
                {
                    mgresourceidentifier childresid = new mgresourceidentifier(featureresid.tostring());
                    string childfeatureclassname = schemaname.split(':')[1];
                    string childupdatingfilter = string.format("uid={0}", propertiescollection["uid"].value);
                    childresid.setname(childfeatureclassname);
                    updatingfeature(childresid, schemaname, childupdatingfilter, childproperties);
                }
                return;
            }
            else
            {
                updatingfeature(featureresid, featureclassname, filter, propertiescollection);
            }
        }
        */
        private void UpdatingFeature(MgResourceIdentifier featureResId, string FeatureClassName, string Filter, Dictionary<string, FeatProperty> propCollection)
        {
            string _filter = "FeatId LIKE '%%'";

            MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
            queryOptions.SetFilter(_filter);

            MgFeatureReader featureReader = mSiteUtilities.FeatureService.SelectFeatures(featureResId, FeatureClassName.Split(':')[1], null);

            featureReader = mSiteUtilities.FeatureService.SelectFeatures(featureResId, FeatureClassName.Split(':')[1], queryOptions);

            featureReader.ReadNext();
            //---------------------------------
            //-----lets start update
            //---------------------------------
            MgFeatureCommandCollection updCommands = new MgFeatureCommandCollection();

            MgPropertyCollection properties = new MgPropertyCollection();
            foreach (var item in propCollection)
            {
                try
                {
                    MgProperty prop = item.Value.GenerateProperty();
                    if (prop != null)
                    {
                        prop.Name = item.Key;
                        properties.Add(prop);
                    }
                }
                catch (InvalidOperationException)
                { }
            }

            if (FeatureClassName == string.Empty)
                FeatureClassName = mLayer.FeatureClassName;
            if (properties.Count > 0)
            {
                MgUpdateFeatures updateCommand = new MgUpdateFeatures(FeatureClassName, properties, Filter);
                updCommands.Add(updateCommand);

                MgPropertyCollection res = mSiteUtilities.FeatureService.UpdateFeatures(featureResId, updCommands, false);

                mSiteUtilities.Map.Save(mSiteUtilities.ResourceService);
                //---------------------------------
                //-----end of update
                //---------------------------------
                //====================================================================
            }
            featureReader.Close();
        }
コード例 #21
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����Ҫ�ض���
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    public bool UpdateFeature(ParcelProperty newFeatureValue)
    {
        MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        MgFeatureQueryOptions query = new MgFeatureQueryOptions();
        string filterString = "Autogenerated_SDF_ID = " + newFeatureValue.ID;
        query.SetFilter(filterString);
        MgResourceIdentifier resId = new MgResourceIdentifier("Library://MgTutorial/Data/Parcels.FeatureSource");
        MgFeatureReader featureReader = featService.SelectFeatures(resId, "Parcels", query);

        if (featureReader.ReadNext())
        {
            featureReader.Close();
            MgPropertyCollection properties = buildPropertyCol(newFeatureValue);

            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            commands.Add(new MgUpdateFeatures("SHP_Schema:Parcels", properties, filterString));
            featService.UpdateFeatures(resId, commands, false);
            return true;
        }
        featureReader.Close();
        return false;
    }
コード例 #22
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�ɾ��Ҫ�ض���
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    public bool RemoveSelectedParcels(string selectString)
    {
        MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        MgMap map = new MgMap();
        map.Open(resService, "Sheboygan");

        MgLayer layer = getLayerByName(map, "Parcels");
        MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
        commands.Add(new MgDeleteFeatures("Parcels", selectString));
        MgResourceIdentifier resId = new MgResourceIdentifier(layer.GetFeatureSourceId());
        featService.UpdateFeatures(resId, commands, false);
        return true;
    }
コード例 #23
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ�����һ����ΪtempParcel����ʱ��
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    public void createTempParcels(MgPolygon geom, ParcelProperty newParcel, string sessionId)
    {
        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);

        // ��ȡ��ͼ����
        MgMap map = new MgMap();
        map.Open(resService, "Sheboygan");
        // ������ʱ��
           MgResourceIdentifier tempLayerSourceId = new MgResourceIdentifier("Session:" + sessionId + "//tempParcel.FeatureSource");

        MgLayer tempParcelLayer = getLayerByName(map, "TempParcels");
        if (tempParcelLayer == null)
        {
            createTempParcelFeatureSource(featureService, tempLayerSourceId);
            tempParcelLayer = createTempParcelLayer(resService, tempLayerSourceId, sessionId);
            map.GetLayers().Insert(0, tempParcelLayer);
        }

        //��Ҫ��Դ�в���Ҫ������
        MgPropertyCollection props = populateParcelFeatureAttributes(geom, newParcel);
        MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
        commands.Add(new MgInsertFeatures("tempParcel", props));
        featureService.UpdateFeatures(tempLayerSourceId, commands, false);

        tempParcelLayer.SetVisible(true);
        tempParcelLayer.ForceRefresh();
        map.Save(resService);
    }
コード例 #24
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ������ʱ��
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public bool CreatePointsLayer(String rootPath, String sessionId)
    {
        // ��ȡҪ�ط������Դ����
        MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        //  �򿪵�ͼ
        MgMap map = new MgMap();
        map.Open(resourceService, "Sheboygan");
        // ---Ҫ�����Ҫ�ز������û��������������滹Ҫ���ܣ�--��ʼ
        // ���������ݵ�Ҫ��Դ
        CreateFeatureSource(sessionId);
        String featureSourceName = "Session:" + sessionId + "//Points.FeatureSource";
        MgResourceIdentifier resourceIdentifier = new MgResourceIdentifier(featureSourceName);

        MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
        MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
        MgGeometryFactory geometryFactory = new MgGeometryFactory();

        // �������¼
        MgPropertyCollection propertyCollection = MakePoint("Point A", -87.727, 43.748);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point B", -87.728, 43.730);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point C", -87.726, 43.750);
        batchPropertyCollection.Add(propertyCollection);

        propertyCollection = MakePoint("Point D", -87.728, 43.750);
        batchPropertyCollection.Add(propertyCollection);

        // ��������Ҫ��������ӵ�Ҫ��Դ
        MgInsertFeatures Insertcmd = new MgInsertFeatures("Points", batchPropertyCollection);
        MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
        featureCommandCollection.Add(Insertcmd);
        featureService.UpdateFeatures(resourceIdentifier, featureCommandCollection, false);
        MgResourceIdentifier resourceID = null;
        //--------------Ҫ�����Ҫ�ز��� ����

        // �����㣬ͨ���㹤��LayerDefinitionFactory
        LayerDefinitionFactory factory = new LayerDefinitionFactory();
        factory.RootDirectoryPath = rootPath;

        //-------------------��������ʽ------------------------//
        // ������Ƿ���l
        string resourceSymbel = "Library://MgTutorial/Symbols/BasicSymbols.SymbolLibrary";
        string symbolName = "PushPin";
        string width = "24";  // unit = points
        string height = "24"; // unit = points
        string color = "FFFF0000";
        string markSymbol = factory.CreateMarkSymbol(resourceSymbel, symbolName, width, height, color);

        // �����ı�
        string text = "ID";
        string fontHeight = "12";
        string foregroundColor = "FF000000";
        string textSymbol = factory.CreateTextSymbol(text, fontHeight, foregroundColor);

        // ���������
        string legendLabel = "trees";
        string filter = "";
        string pointRule = factory.CreatePointRule(legendLabel, filter, textSymbol, markSymbol);

        // ��������ʽ
        string pointTypeStyle = factory.CreatePointTypeStyle(pointRule);

        // �������ŷ�Χ
        string minScale = "0";
        string maxScale = "1000000000000";
        string pointScaleRange = factory.CreateScaleRange(minScale, maxScale, pointTypeStyle);

        // �����㶨��
        string featureName = "PointSchema:Points";
        string geometry = "GEOM";
        string layerDefinition = factory.CreateLayerDefinition(featureSourceName, featureName, geometry, pointScaleRange);

        MgByteSource byteSource = new MgByteSource(Encoding.UTF8.GetBytes(layerDefinition), layerDefinition.Length);
        MgByteReader byteReader = byteSource.GetReader();

        resourceID = new MgResourceIdentifier("Session:" + sessionId + "//Points.LayerDefinition");
        resourceService.SetResource(resourceID, byteReader, null);
        //��������IJ㶨�����ݣ������ã�
        MgByteSink byteSink = new MgByteSink(resourceService.GetResourceContent(resourceID));
        string filePath = "C:\\Temp\\LayerDefinition.xml";
        byteSink.ToFile(filePath);

        // �����㲢��ӵ�����͵�ͼ��
        MgLayer newLayer = CreateLayerResource(resourceID, resourceService, "Points", "��ʱ��", map);

        AddLayerToGroup(newLayer, "Analysis", "����", map);

        MgLayerCollection layerCollection = map.GetLayers();
        if (layerCollection.Contains("Points"))
        {
            MgLayer pointsLayer = layerCollection.GetItem("Points");
            pointsLayer.SetVisible(true);
        }
        // �����ͼ
        map.Save(resourceService);

        return true;
    }
コード例 #25
0
ファイル: Feature.cs プロジェクト: ranyaof/Meuhedet
 private void UpdatingFeature(MgResourceIdentifier featureResId, string featureClassName, string filter, Dictionary<string, FeatureProperty> propCollection)
 {
     MgFeatureCommandCollection updCommands = new MgFeatureCommandCollection();
     MgPropertyCollection properties = new MgPropertyCollection();
     MgPropertyCollection properties2Log = new MgPropertyCollection();
     if (this.InsertToLog)
     {
         properties2Log.Add(new MgInt32Property("ItemId", this.FeatId));
     }
     foreach (KeyValuePair<string, FeatureProperty> item in propCollection)
     {
         try
         {
             MgProperty prop = item.Value.GenerateProperty();
             MgProperty prop4Log = item.Value.GenerateProperty(false);
             if (prop4Log != null)
             {
                 prop4Log.Name = item.Key;
                 if (this.InsertToLog)
                 {
                     properties2Log.Add(prop4Log);
                 }
             }
             if (prop != null)
             {
                 prop.Name = item.Key;
                 properties.Add(prop);
             }
         }
         catch (InvalidOperationException)
         {
         }
     }
     if (featureClassName == string.Empty)
     {
         featureClassName = this.Layer.FeatureClassName;
     }
     if (properties.Count > 0)
     {
         MgUpdateFeatures updateCommand = new MgUpdateFeatures(featureClassName, properties, filter);
         updCommands.Add(updateCommand);
         if (this.InsertToLog)
         {
             MgInsertFeatures insert = new MgInsertFeatures(featureClassName + "Log", properties2Log);
             updCommands.Add(insert);
         }
         this._helper.FeatureService.UpdateFeatures(featureResId, updCommands, false);
         this._helper.Map.Save(this._helper.ResourceService);
     }
 }
コード例 #26
0
ファイル: UtilityClass.cs プロジェクト: guchanghai/Cut
    //----------------------------------------------------------------------------------------
    // �� �ܣ� �ͷ�����
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    void ReleaseReader(MgPropertyCollection res, MgFeatureCommandCollection commands)
    {
        if (res == null)
            return;

        for (int i = 0; i < res.GetCount(); i++)
        {
            MgFeatureCommand cmd = commands.GetItem(i);
            if (cmd is MgInsertFeatures)
            {
                MgFeatureProperty resProp = res.GetItem(i) as MgFeatureProperty;
                if (resProp != null)
                {
                    MgFeatureReader reader = resProp.GetValue() as MgFeatureReader;
                    if (reader == null)
                        return;
                    reader.Close();
                }
            }
        }
    }
コード例 #27
0
ファイル: Util.cs プロジェクト: kanbang/Colt
 public static void ClearDataSource(MgFeatureService featSvc, MgResourceIdentifier fsId, String featureName)
 {
     MgDeleteFeatures deleteCmd = new MgDeleteFeatures(featureName, "ID >= 0"); //NOXLATE
     MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
     commands.Add(deleteCmd);
     featSvc.UpdateFeatures(fsId, commands, false);
 }
コード例 #28
0
ファイル: AnalyzingFeatures.cs プロジェクト: achilex/MgDev
        private void btnFindFeaturesInBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase           selection      = _viewer.GetSelection();
            MgReadOnlyLayerCollection selectedLayers = selection.GetLayers();

            if (selectedLayers == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }
            MgLayerBase parcels = null;

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                MgLayerBase layer = selectedLayers.GetItem(i);
                if (layer.Name == "Parcels")
                {
                    parcels = layer;
                    break;
                }
            }
            if (parcels == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }

            int bufferRingSize = 500; // measured in metres

            // Set up some objects for coordinate conversion

            MgMapBase           map             = _viewer.GetMap();
            MgLayerCollection   mapLayers       = map.GetLayers();
            MgMapViewerProvider provider        = _viewer.GetProvider();
            MgResourceService   resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);
            string           sessionId      = Guid.NewGuid().ToString();

            String                    mapWktSrs               = map.GetMapSRS();
            MgAgfReaderWriter         agfReaderWriter         = new MgAgfReaderWriter();
            MgWktReaderWriter         wktReaderWriter         = new MgWktReaderWriter();
            MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem        srs        = coordinateSystemFactory.Create(mapWktSrs);
            MgMeasure                 srsMeasure = srs.GetMeasure();

            // Check for a buffer layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the buffer.

            BufferHelper helper      = new BufferHelper();
            MgdLayer     bufferLayer = null;
            int          layerIndex  = map.GetLayers().IndexOf("Buffer");

            if (layerIndex < 0)
            {
                // The layer does not exist and must be created.

                MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
                helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
                bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
                map.GetLayers().Insert(0, bufferLayer);
            }
            else
            {
                bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                bufferLayer.DeleteFeatures("ID like '%'");
            }

            // Check for a parcel marker layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the parcel markers.

            MgdLayer parcelMarkerLayer = null;

            layerIndex = map.GetLayers().IndexOf("ParcelMarker");
            if (layerIndex < 0)
            {
                MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource");
                helper.CreateParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId);
                parcelMarkerLayer = helper.CreateParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId);
                map.GetLayers().Insert(0, parcelMarkerLayer);
            }
            else
            {
                parcelMarkerLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                parcelMarkerLayer.DeleteFeatures("ID like '%'");
            }

            // Check each layer in the selection.

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                // Only check selected features in the Parcels layer.

                MgdLayer layer = (MgdLayer)selectedLayers.GetItem(i);

                if (layer.GetName() == "Parcels")
                {
                    string geomName = layer.GetFeatureGeometryName();
                    System.Diagnostics.Trace.TraceInformation("Marking all parcels inside the buffer that are of type 'MFG'");

                    MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);


                    // Process each item in the MgFeatureReader. Get the
                    // geometries from all the selected features and
                    // merge them into a single geometry.

                    MgGeometryCollection inputGeometries = new MgGeometryCollection();
                    while (featureReader.ReadNext())
                    {
                        MgByteReader featureGeometryData = featureReader.GetGeometry(geomName);
                        MgGeometry   featureGeometry     = agfReaderWriter.Read(featureGeometryData);

                        inputGeometries.Add(featureGeometry);
                    }

                    MgGeometryFactory geometryFactory  = new MgGeometryFactory();
                    MgGeometry        mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);

                    // Create a buffer from the merged geometries

                    double     bufferDist     = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize);
                    MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                    // Create a filter to select parcels within the buffer. Combine
                    // a basic filter and a spatial filter to select all parcels
                    // within the buffer that are of type "MFG".

                    MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
                    queryOptions.SetFilter("RTYPE = 'MFG'");
                    queryOptions.SetSpatialFilter(geomName, bufferGeometry, MgFeatureSpatialOperations.Inside);

                    featureReader = layer.SelectFeatures(queryOptions);

                    // Get the features from the feature source,
                    // determine the centroid of each selected feature, and
                    // add a point to the ParcelMarker layer to mark the
                    // centroid.
                    // Collect all the points into an MgFeatureCommandCollection,
                    // so they can all be added in one operation.

                    MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection();
                    int inserted = 0;
                    while (featureReader.ReadNext())
                    {
                        MgByteReader byteReader = featureReader.GetGeometry(geomName);
                        MgGeometry   geometry   = agfReaderWriter.Read(byteReader);
                        MgPoint      point      = geometry.GetCentroid();

                        // Create an insert command for this parcel.
                        MgPropertyCollection properties = new MgPropertyCollection();
                        properties.Add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.Write(point)));
                        //parcelMarkerCommands.Add(new MgInsertFeatures("ParcelMarkerClass", properties));
                        MgFeatureReader fr = parcelMarkerLayer.InsertFeatures(properties);
                        fr.Close();
                        inserted++;
                    }
                    featureReader.Close();

                    if (inserted == 0)
                    {
                        MessageBox.Show("No parcels within the buffer area match.");
                        return;
                    }

                    // Create a feature in the buffer feature source to show the area covered by the buffer.

                    MgPropertyCollection props = new MgPropertyCollection();
                    props.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));
                    bufferLayer.InsertFeatures(props);

                    // Ensure that the buffer layer is visible and in the legend.

                    bufferLayer.SetVisible(true);
                    bufferLayer.ForceRefresh();
                    bufferLayer.SetDisplayInLegend(true);
                    parcelMarkerLayer.SetVisible(true);
                    parcelMarkerLayer.ForceRefresh();

                    MessageBox.Show("Done");
                    _viewer.RefreshMap();
                    IMapLegend legend = Shell.Instance.Legend;
                    if (legend != null)
                    {
                        legend.RefreshLegend();
                    }
                }
            }
        }
コード例 #29
0
ファイル: LocalNativeConnection.cs プロジェクト: kanbang/Colt
        internal void InsertFeatures(MgResourceIdentifier fsId, string className, MgPropertyCollection props)
        {
            try
            {
                MgFeatureCommandCollection cmds = new MgFeatureCommandCollection();
                MgInsertFeatures insert = new MgInsertFeatures(className, props);
                cmds.Add(insert);

                MgFeatureService fs = (MgFeatureService)this.Connection.CreateService(MgServiceType.FeatureService);
                MgPropertyCollection result = fs.UpdateFeatures(fsId, cmds, false);

                ((MgFeatureProperty)result.GetItem(0)).GetValue().Close();
            }
            catch (MgException ex)
            {
                var exMgd = new FeatureServiceException(ex.Message);
                exMgd.MgErrorDetails = ex.GetDetails();
                exMgd.MgStackTrace = ex.GetStackTrace();
                ex.Dispose();
                throw exMgd;
            }
        }
コード例 #30
0
ファイル: AnalyzingFeatures.cs プロジェクト: kanbang/Colt
        private void btnFindFeaturesInBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase selection = _viewer.GetSelection();
            MgReadOnlyLayerCollection selectedLayers = selection.GetLayers();
            if (selectedLayers == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }
            MgLayerBase parcels = null;
            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                MgLayerBase layer = selectedLayers.GetItem(i);
                if (layer.Name == "Parcels")
                {
                    parcels = layer;
                    break;
                }
            }
            if (parcels == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }

            int bufferRingSize = 500; // measured in metres

            // Set up some objects for coordinate conversion

            MgMapBase map = _viewer.GetMap();
            MgLayerCollection mapLayers = map.GetLayers();
            MgMapViewerProvider provider = _viewer.GetProvider();
            MgResourceService resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);
            string sessionId = Guid.NewGuid().ToString();

            String mapWktSrs = map.GetMapSRS();
            MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
            MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
            MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem srs = coordinateSystemFactory.Create(mapWktSrs);
            MgMeasure srsMeasure = srs.GetMeasure();

            // Check for a buffer layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the buffer.

            BufferHelper helper = new BufferHelper();
            MgdLayer bufferLayer = null;
            int layerIndex = map.GetLayers().IndexOf("Buffer");
            if (layerIndex < 0)
            {
                // The layer does not exist and must be created.

                MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
                helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
                bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
                map.GetLayers().Insert(0, bufferLayer);
            }
            else
            {
                bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                bufferLayer.DeleteFeatures("ID like '%'");
            }

            // Check for a parcel marker layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the parcel markers.

            MgdLayer parcelMarkerLayer = null;
            layerIndex = map.GetLayers().IndexOf("ParcelMarker");
            if (layerIndex < 0)
            {
                MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource");
                helper.CreateParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId);
                parcelMarkerLayer = helper.CreateParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId);
                map.GetLayers().Insert(0, parcelMarkerLayer);
            }
            else
            {
                parcelMarkerLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                parcelMarkerLayer.DeleteFeatures("ID like '%'");
            }

            // Check each layer in the selection.

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                // Only check selected features in the Parcels layer.

                MgdLayer layer = (MgdLayer)selectedLayers.GetItem(i);

                if (layer.GetName() == "Parcels")
                {
                    string geomName = layer.GetFeatureGeometryName();
                    System.Diagnostics.Trace.TraceInformation("Marking all parcels inside the buffer that are of type 'MFG'");

                    MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);


                    // Process each item in the MgFeatureReader. Get the
                    // geometries from all the selected features and
                    // merge them into a single geometry.

                    MgGeometryCollection inputGeometries = new MgGeometryCollection();
                    while (featureReader.ReadNext())
                    {
                        MgByteReader featureGeometryData = featureReader.GetGeometry(geomName);
                        MgGeometry featureGeometry = agfReaderWriter.Read(featureGeometryData);

                        inputGeometries.Add(featureGeometry);
                    }

                    MgGeometryFactory geometryFactory = new MgGeometryFactory();
                    MgGeometry mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);

                    // Create a buffer from the merged geometries

                    double bufferDist = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize);
                    MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                    // Create a filter to select parcels within the buffer. Combine
                    // a basic filter and a spatial filter to select all parcels
                    // within the buffer that are of type "MFG".

                    MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
                    queryOptions.SetFilter("RTYPE = 'MFG'");
                    queryOptions.SetSpatialFilter(geomName, bufferGeometry, MgFeatureSpatialOperations.Inside);

                    featureReader = layer.SelectFeatures(queryOptions);

                    // Get the features from the feature source,
                    // determine the centroid of each selected feature, and
                    // add a point to the ParcelMarker layer to mark the
                    // centroid.
                    // Collect all the points into an MgFeatureCommandCollection,
                    // so they can all be added in one operation.

                    MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection();
                    int inserted = 0;
                    while (featureReader.ReadNext())
                    {
                        MgByteReader byteReader = featureReader.GetGeometry(geomName);
                        MgGeometry geometry = agfReaderWriter.Read(byteReader);
                        MgPoint point = geometry.GetCentroid();

                        // Create an insert command for this parcel.
                        MgPropertyCollection properties = new MgPropertyCollection();
                        properties.Add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.Write(point)));
                        //parcelMarkerCommands.Add(new MgInsertFeatures("ParcelMarkerClass", properties));
                        MgFeatureReader fr = parcelMarkerLayer.InsertFeatures(properties);
                        fr.Close();
                        inserted++;
                    }
                    featureReader.Close();

                    if (inserted == 0)
                    {
                        MessageBox.Show("No parcels within the buffer area match.");
                        return;
                    }

                    // Create a feature in the buffer feature source to show the area covered by the buffer.

                    MgPropertyCollection props = new MgPropertyCollection();
                    props.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));
                    bufferLayer.InsertFeatures(props);

                    // Ensure that the buffer layer is visible and in the legend.

                    bufferLayer.SetVisible(true);
                    bufferLayer.ForceRefresh();
                    bufferLayer.SetDisplayInLegend(true);
                    parcelMarkerLayer.SetVisible(true);
                    parcelMarkerLayer.ForceRefresh();

                    MessageBox.Show("Done");
                    _viewer.RefreshMap();
                    IMapLegend legend = Shell.Instance.Legend;
                    if (legend != null)
                        legend.RefreshLegend();
                }
            }
        }
コード例 #31
0
ファイル: LocalNativeConnection.cs プロジェクト: kanbang/Colt
        internal int UpdateFeatures(MgResourceIdentifier fsId, string className, MgPropertyCollection props, string filter)
        {
            try
            {
                MgFeatureCommandCollection cmds = new MgFeatureCommandCollection();
                MgUpdateFeatures update = new MgUpdateFeatures(className, props, filter);
                cmds.Add(update);

                MgFeatureService fs = (MgFeatureService)this.Connection.CreateService(MgServiceType.FeatureService);
                MgPropertyCollection result = fs.UpdateFeatures(fsId, cmds, false);

                var ip = result.GetItem(0) as MgInt32Property;
                if (ip != null)
                    return ip.GetValue();
                return -1;
            }
            catch (MgException ex)
            {
                var exMgd = new FeatureServiceException(ex.Message);
                exMgd.MgErrorDetails = ex.GetDetails();
                exMgd.MgStackTrace = ex.GetStackTrace();
                ex.Dispose();
                throw exMgd;
            }
        }
コード例 #32
0
    public bool ShowSpatialFilter()
    {
        bool result = true;
        MgUserInformation userInfo = new MgUserInformation(Request["SESSION"]);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);

        MgResourceIdentifier sdfResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.FeatureSource");

        MgResourceService resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;
        MgFeatureService featureService = siteConnection.CreateService(MgServiceType.FeatureService) as MgFeatureService;

        MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

        MgMap map = new MgMap();
        map.Open(resourceService, Request["MAPNAME"]);

        MgLayer layer = null;
        MgLayerCollection layers = map.GetLayers();
        if (layers.Contains("_QuerySpatialFilter"))
        {
            layer = (MgLayer)layers.GetItem("_QuerySpatialFilter");
            //updateCommands.Add(new MgDeleteFeatures("Filter", "ID > 0"));
        }
        else
        {
            // Create the Feature Source (SDF)

            MgFeatureSchema sdfSchema = this.CreateFilterSchema();
            MgCreateSdfParams sdfParams = new MgCreateSdfParams("MAPCS", map.GetMapSRS(), sdfSchema);
            featureService.CreateFeatureSource(sdfResId, sdfParams);

            // Create the Layer

            MgResourceIdentifier layerResId = new MgResourceIdentifier("Session:" + Request["SESSION"] + "//Filter.LayerDefinition");
            String layerDefinition = File.ReadAllText(GetQueryXmlTemplatePath());
            layerDefinition = layerDefinition.Replace("%s", sdfResId.ToString());

            MgByteReader reader = new MgByteReader(layerDefinition, "text/xml");
            resourceService.SetResource(layerResId, reader, null);

            layer = new MgLayer(layerResId, resourceService);

            layer.SetName("_QuerySpatialFilter");
            layer.SetLegendLabel("תחום זמני");
            layer.SetDisplayInLegend(true);
            layer.SetSelectable(true);
            layer.ForceRefresh();
            layer.NeedsRefresh();

            layers.Insert(0, layer);
        }

        // Make the layer visible

        layer.SetVisible(true);
        map.Save(resourceService);

        // Add the geometry to the filter feature source
        MgPolygon polygon = this.CreatePolygonFromGeomText(Request["GEOMTEXT"].ToString());
        MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();
        MgByteReader byteReader = agfWriter.Write(polygon);

        MgPropertyCollection propertyValues = new MgPropertyCollection();
        propertyValues.Add(new MgGeometryProperty("Geometry", byteReader));
        try
        {
            updateCommands.Add(new MgInsertFeatures("Filter", propertyValues));

            featureService.UpdateFeatures(sdfResId, updateCommands, false);
        }
        catch { }

        return result;
    }
コード例 #33
0
ファイル: RedlineRegistry.cs プロジェクト: kanbang/Colt
        internal void DeleteLayer(RedlineLayer layer)
        {
            var regId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgDeleteFeatures delete = new MgDeleteFeatures("Default:MarkupRegistry", "ResourceId = '" + layer.FeatureSource + "'");
            commands.Add(delete);

            MgPropertyCollection results = _featSvc.UpdateFeatures(regId, commands, false);
            MgInt32Property deleteResult = results.GetItem(0) as MgInt32Property;
            if (deleteResult != null && deleteResult.GetValue() > 0)
            {
                var ldfId = new MgResourceIdentifier(layer.LayerDefinition);
                var fsId = new MgResourceIdentifier(layer.FeatureSource);

                if (_resSvc.ResourceExists(ldfId))
                    _resSvc.DeleteResource(ldfId);

                if (_resSvc.ResourceExists(fsId))
                    _resSvc.DeleteResource(fsId);
            }
        }
コード例 #34
0
 public void DeleteFeature(int featId)
 {
     MgDeleteFeatures delete = new MgDeleteFeatures("Maintenance", string.Format("FeatId={0}", featId));
     MgDeleteFeatures deleteLog = new MgDeleteFeatures("MaintenanceLog", string.Format("ItemId={0}", featId));
     MgFeatureCommandCollection commands = new MgFeatureCommandCollection {
     delete,
     deleteLog
     };
     this._helper.FeatureService.UpdateFeatures(this._sdfResId, commands, false);
 }
コード例 #35
0
ファイル: MarkupEditor.cs プロジェクト: ranyaof/Meuhedet
        public bool DeleteMarkup()
        {
            MgResourceIdentifier featureSourceId = new MgResourceIdentifier(libraryPath + this.GetMarkupName() + ".FeatureSource");

            MgMap map = new MgMap();
            map.Open(_resourceService, GetParameter(this.args, "MAPNAME"));

            string path = map.MapDefinition.Path;
            if (path.ToLower().EndsWith("maps")) path = path.Substring(0, path.Length - 4);
            libraryPath = ConfigurationManager.AppSettings["MarkupLibraryPath"].ToString();
            path =libraryPath +"Maintenance/Data/Maintenance.FeatureSource";

            MgResourceIdentifier maintenanceResId = new MgResourceIdentifier(path);

            //Check related entries in maintenance
            if (MaintenanceForFeatureExists(featureSourceId, maintenanceResId)) return false;
            DeleteProjectDataFormDatabase(featureSourceId, GetParameter(this.args, "MARKUPFEATURE"));
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            commands.Add(new MgDeleteFeatures("Markup", "ID = " + GetParameter(this.args, "MARKUPFEATURE")));

            _featureService.UpdateFeatures(featureSourceId, commands, false);

            return true;
        }
コード例 #36
0
ファイル: MarkupEditor.cs プロジェクト: ranyaof/Meuhedet
        public void InsertMarkupFeature(MgPropertyCollection propertyValues)
        {
            MgResourceIdentifier featureSourceId = new MgResourceIdentifier(libraryPath + this.GetMarkupName() + ".FeatureSource");

            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            commands.Add(new MgInsertFeatures("Markup", propertyValues));

            _featureService.UpdateFeatures(featureSourceId, commands, false);
               /* int projectId = GetProjectId();
            if (projectId > 0)
            {
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ProjectManagerConnectionString"].ConnectionString))
                {
                    var cmd = conn.CreateCommand();
                    cmd.CommandText = String.Format("INSERT INTO Projects(UID, Name, ProjectId, StatusId, ManagerId) VALUES({0}, @Name, {1}, 9, 14)", GetLastUID(featureSourceId), projectId);
                    var nameParam = new System.Data.SqlClient.SqlParameter
                    {
                        ParameterName = "@Name",
                        SqlDbType = System.Data.SqlDbType.NVarChar,
                        Size = 50,
                        Value = GetParameter(this.args, "TEXT")
                    };
                    cmd.Parameters.Add(nameParam);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }*/
        }
コード例 #37
0
ファイル: MarkupEditor.cs プロジェクト: ranyaof/Meuhedet
        public void UpdateMarkup()
        {
            MgResourceIdentifier featureSourceId = new MgResourceIdentifier(libraryPath + this.GetMarkupName() + ".FeatureSource");

            MgPropertyCollection propertyValues = new MgPropertyCollection();
            propertyValues.Add(new MgStringProperty("Text", GetParameter(this.args, "UPDATETEXT")));
            propertyValues.Add(new MgStringProperty("ReverseText", ReverseString(GetParameter(this.args, "UPDATETEXT"))));

            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            commands.Add(new MgUpdateFeatures("Markup", propertyValues, "ID = " + GetParameter(this.args, "MARKUPFEATURE")));
            _featureService.UpdateFeatures(featureSourceId, commands, false);

            /*int projectId = GetProjectId();
            if (projectId > 0)
            {
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ProjectManagerConnectionString"].ConnectionString))
                {
                    var cmd = conn.CreateCommand();
                    cmd.CommandText = String.Format("UPDATE Projects SET Name = @Name WHERE ProjectId={0} AND UID={1}", projectId, GetParameter(this.args, "MARKUPFEATURE"));
                    var nameParam = new System.Data.SqlClient.SqlParameter
                                    {
                                        ParameterName="@Name",
                                        SqlDbType = System.Data.SqlDbType.NVarChar,
                                        Size=50,
                                        Value = GetParameter(this.args, "UPDATETEXT")
                                    };
                    cmd.Parameters.Add(nameParam);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }*/
        }
コード例 #38
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());
            }
        }
コード例 #39
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Xcoord.Value) || string.IsNullOrEmpty(Ycoord.Value) || string.IsNullOrEmpty(kanam.Value))
            {
               //   Response.Write("<script type='text/javascript'>try{ zoom();}catch(e){}</script>");
                ClientScript.RegisterStartupScript(GetType(), "zoomme", "<script>try{ zoomzfd();}catch(e){}</script>");
              return;
            }

            /*

             String mgSessionId = GetRequestParameters()["SESSION"];
             String mgMap = GetRequestParameters()["map"];
             //GeocodeAddress addr = null;
             bool success = false;
             decimal LatInput=0;
             decimal LonInput=0;*/

                // Initialize the web-extensions and connect to the Site using
                // the session identifier passed in the query string.

            try
            {

                InitializeWebTier();
                //MgUserInformation userInfo = new MgUserInformation(mgSessionId);

              //  mgSessionId = site.CreateSession();
                MgUserInformation userInfo = new MgUserInformation(mgSessionId);
                MgSiteConnection siteConnection = new MgSiteConnection();
               siteConnection.Open(userInfo);
                decimal LatInput = System.Convert.ToDecimal(Xcoord.Value);
                decimal LonInput = System.Convert.ToDecimal(Ycoord.Value);
                /* LatInput = System.Convert.ToDecimal(GetRequestParameters()["LatInput"]);
                 LonInput = System.Convert.ToDecimal(GetRequestParameters()["LonInput"]);*/

                // Make the request to geocoder.us passing the address.
                //addr = requestGeocodeAddress(address);

                if (LatInput != 0 && LonInput != 0)
                {
                      //Request the specified address to the geocode service using REST, the
            // GET interface
            //

                    if (targetsnew.InnerHtml == "")
                    {
                        targetsnewTitle.InnerHtml = "מיקום נוכחי :";
                        targetsoldTitle.InnerHtml = "";
                        targetsnew.InnerHtml = "<table>";
                        targetsnew.InnerHtml += "<tr><td><img src=\"../images/pushpinblue.jpg\">";
                        targetsnew.InnerHtml += "<a href=\"gotopoint.aspx?X=" + LonInput + "&Y=" + LatInput + "&Scale=2000\" target=\"scriptFrame\">  מיקום נמצא </a></td></tr>";
                        targetsnew.InnerHtml += "<tr><td align=left>X: " + LonInput + "</td></tr>";
                        targetsnew.InnerHtml += "<tr><td align=left>Y: " + LatInput + "<hr></td></tr>";
                        targetsnew.InnerHtml += "</table>";
                    }
                    else
                    {
                        targetsoldTitle.InnerHtml = "מיקום קודם :";
                        targetsold.InnerHtml += targetsnew.InnerHtml;
                        targetsnew.InnerHtml = "<table>";
                        targetsnew.InnerHtml += "<tr><td><img src=\"../images/pushpinblue.jpg\">";
                        targetsnew.InnerHtml += "<a href=\"gotopoint.aspx?X=" + LonInput + "&Y=" + LatInput + "&Scale=2000\" target=\"scriptFrame\">  מיקום נמצא </a></td></tr>";
                        targetsnew.InnerHtml += "<tr><td align=left>X: " + LonInput + "</td></tr>";
                        targetsnew.InnerHtml += "<tr><td align=left>Y: " + LatInput + "<hr></td></tr>";
                        targetsnew.InnerHtml += "</table>";

                    }
                    // The geocode successfully returned a location.

                    //if (IsDebugAssembly(this.GetType().Assembly))
                    //    System.Diagnostics.Debugger.Launch();
                    MgResourceService resourceService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
                    MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

                    MgMap map = new MgMap();
                  map.Open(resourceService, mgMap);
                 //   map.Open(mgMap);
                    // Check the map for the AddressMarker layer. If it does not
                    // exist then create a feature source to store address results
                    // and a layer to display them.
                    MgResourceIdentifier locationMarkerDataResId = new MgResourceIdentifier("Session:" + mgSessionId + "//LocationMarker.FeatureSource");
                  //  Session:7f4231a2-0d7e-11e2-8000-000c294ca3a6_en_7F0000010AFC0AFB0AFA//a2f5e4fb-0c3c-4ee7-bb5d-c8f4a226a68b.FeatureSource
                   // MgResourceIdentifier locationMarkerDataResId = new MgResourceIdentifier("Library://rany1/Data/findLocation/temp/LocationMarker.FeatureSource");
                  //  string layerDef = "Session:" + mgSessionId + "//LocationMarker.FeatureSource";
                    //string dataSource = "Library://rany1/Data/LocationMarker.FeatureSource";

                    /*string layerDef  = "Library://rany1/Layers/LocationMarker.LayerDefinition";

                    MgLayerCollection colLays = map.GetLayers();

                    MgLayer layer = FindLayer(colLays, layerDef);*/

                    ////                       MgLayer locationLayer = FindLayerByName(,"LocationMarker") ;//GetLayerByName(map, "LocationMarker");

                    //MgLayerCollection colLays = map.GetLayers();
                    MgLayerCollection colLays = map.GetLayers();
                    MgLayer locationLayer = FindLayerByName(colLays, "LocationMarker");

                    if (locationLayer == null)
                    {
                       // diverr.InnerHtml += " לא נמצאו שכבות LocationMarker ";
                        lf.CreateLocationMarkerFeatureSource(featureService, locationMarkerDataResId, map);
                        locationLayer = lf.CreateLocationMarkerLayer(resourceService, locationMarkerDataResId, mgSessionId);

                        map.GetLayers().Insert(0, locationLayer);
                    }
                    else if (locationLayer.GetVisible())
                    {
                        // If the layer exists and is visible, then display the
                        // previous results.

                        //EmitAddressResults(featureService, locationMarkerDataResId, mgSessionId, Response);
                        EmitLocationResults(featureService, locationMarkerDataResId, mgSessionId, HttpContext.Current.Response);
                    }

                    // Insert the results of the Geo-Code into the temporary
                    // feature source and ensure the address marker layer
                    // is visible.

                    MgAgfReaderWriter geometryReaderWriter = new MgAgfReaderWriter();
                    MgGeometryFactory geometryFactory = new MgGeometryFactory();
                    MgPoint locationPoint = geometryFactory.CreatePoint(geometryFactory.CreateCoordinateXY(Convert.ToDouble(LonInput), Convert.ToDouble(LatInput)));

                    MgPropertyCollection properties = new MgPropertyCollection();
                    properties.Add(new MgStringProperty("Address", ""));
                    properties.Add(new MgGeometryProperty("Location", geometryReaderWriter.Write(locationPoint)));

                    MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
                    commands.Add(new MgInsertFeatures("LocationMarker", properties));

                    featureService.UpdateFeatures(locationMarkerDataResId, commands, false);

                    locationLayer.SetVisible(true);
                    locationLayer.ForceRefresh();

                    map.Save(resourceService);

                    Response.Write("<script type='text/javascript'>try{ parent.parent.ZoomToView(" + px1.Value + ", " + py1.Value + ", " + kanam.Value + ", true);parent.parent.mapFrame.Refresh();}catch(e){}</script>");
                    /* success = true;*/

                }
                else
                {
                    // Response.Write("<tr><td>נקודת הציון לא נמצאה: <hr></td></tr>");
                }
            }
            catch (MgException eee)
            {
               // Response.Write("<script type='text/javascript'>try{alert('rany'); parent.parent.ZoomToView(" + px1.Value + ", " + py1.Value + ", " + kanam.Value + ", true);parent.parent.mapFrame.Refresh();}catch(e){}</script>");
               // Response.Write("<tr><td>" + eee.GetExceptionMessage() + "</td></tr>");
             //   Response.Write("<tr><td>" + eee.InnerException.Message + "</td></tr>");
                Response.Write("<tr><td>" + eee.ToString() + "</td></tr>");
                Response.Write("<tr><td>" + eee.GetBaseException() + "</td></tr>");
                Response.Write("<tr><td>" + eee.GetStackTrace()+ "</td></tr>");
                Response.Write("<tr><td>" + eee.GetExceptionMessage() + "</td></tr>");

                  Response.Write("<tr><td class=\"Spacer\"></td></tr>");
                 // Response.Write("<tr><td>" + eee.GetDetails() + "</td></tr>");
            }
        }