示例#1
0
        public SpatialContextResultDialog(MgSpatialContextReader reader)
            : this()
        {
            _reader = reader;
            _wktRW  = new MgWktReaderWriter();
            _agfRW  = new MgAgfReaderWriter();

            StringBuilder sb = new StringBuilder();

            while (_reader.ReadNext())
            {
                MgGeometry geom = null;
                if (_reader.ExtentType == MgSpatialContextExtentType.scStatic)
                {
                    geom = _agfRW.Read(_reader.Extent);
                }

                sb.AppendFormat("Spatial Context{0}\tName: {1}{0}\tDescription: {2}{0}\tCoordinate System: {3}{0}\tCoordinate System Wkt: {4}{0}\tExtent Type {5}{0}\tExtents (if applicable): {6}{0}\tXY Tolerance: {7}{0}\tZ Tolerance: {8}{0}\tIs Active: {9}{0}{0}",
                                Environment.NewLine,
                                _reader.Name,
                                _reader.Description,
                                _reader.CoordinateSystem,
                                _reader.CoordinateSystemWkt,
                                _reader.ExtentType == MgSpatialContextExtentType.scDynamic ? "Dynamic" : "Static",
                                geom != null ? _wktRW.Write(geom) : "N/A",
                                _reader.XYTolerance,
                                _reader.ZTolerance,
                                _reader.IsActive());
            }
            textBox1.Text = sb.ToString();
            _reader.Close();
        }
示例#2
0
        public MgMultiGeometry CreateMultiGeometry()
        {
            MgGeometryCollection geometries = new MgGeometryCollection();
            MgGeometry           geometry   = null;

            // CurvePolygon
            geometry = (MgGeometry)CreateCurvePolygon(0, 1);
            geometries.Add(geometry);

            // CurveString
            // Not doing CurveString because of some unfixed defect.
            // It may be the same one that sometimes affects MultiPolygon.
            geometry = (MgGeometry)CreateCurveString(100);
            geometries.Add(geometry);

            // LineString
            geometry = (MgGeometry)CreateLineString(1.0);
            geometries.Add(geometry);

            // Point
            geometry = (MgGeometry)CreatePoint();
            geometries.Add(geometry);

            // Polygon
            geometry = CreatePolygon(0.0);
            geometries.Add(geometry);

            // Make MultiGeometry from the many geometries collected above.
            return(factory.CreateMultiGeometry(geometries));
        }
示例#3
0
        private void InsertRedlineGeometry(MgGeometry geom)
        {
            MgPropertyCollection feature  = new MgPropertyCollection();
            MgByteReader         agf      = _agfRW.Write(geom);
            MgGeometryProperty   geomProp = new MgGeometryProperty("Geometry", agf);

            feature.Add(geomProp);

            _redlineLayer.ForceRefresh();
            var reader   = _redlineLayer.InsertFeatures(feature);
            int inserted = 0;

            while (reader.ReadNext())
            {
                inserted++;
            }
            reader.Close();
            if (inserted > 0)
            {
                _viewer.RefreshMap();
                IMapLegend legend = Shell.Instance.Legend;
                if (legend != null)
                {
                    legend.RefreshLegend();
                }
            }
        }
示例#4
0
        private void OnPointDigitized(double x, double y)
        {
            CheckRedlineLayer();
            MgGeometry point = _geomFact.CreatePoint(_geomFact.CreateCoordinateXY(x, y));

            InsertRedlineGeometry(point);
        }
示例#5
0
文件: MainForm.cs 项目: achilex/MgDev
 private void btnSelectCircle_Click(object sender, EventArgs e)
 {
     mgMapViewer1.DigitizeCircle((x, y, r) =>
     {
         MgGeometry geom = _wktRw.Read(MakeWktCircle(x, y, r));
         mgMapViewer1.SelectByGeometry(geom);
     });
 }
示例#6
0
 private void btnRectangle_Click(object sender, EventArgs e)
 {
     _viewer.DigitizeRectangle((llx, lly, urx, ury) =>
     {
         ClearFilterGeometry();
         _filterGeometry = _wktRw.Read(Util.MakeWktPolygon(llx, lly, urx, ury));
         lblSpatialFilterGeomSet.Visible = true;
     });
 }
示例#7
0
        private void btnSelectDistrict1_Click(object sender, EventArgs e)
        {
            MgMapBase         map       = _viewer.GetMap();
            MgLayerCollection layers    = map.GetLayers();
            MgLayerBase       districts = layers.GetItem("Districts");
            MgLayerBase       parcels   = layers.GetItem("Parcels");

            //Query the geometry of district 1
            MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();

            districtQuery.SetFilter("Autogenerated_SDF_ID = 1");

            MgFeatureReader   reader       = districts.SelectFeatures(districtQuery);
            MgGeometry        districtGeom = null;
            MgAgfReaderWriter agfRw        = new MgAgfReaderWriter();

            try
            {
                reader.ReadNext();
                MgByteReader geomAgf = reader.GetGeometry(districts.GetFeatureGeometryName());
                districtGeom = agfRw.Read(geomAgf);
            }
            finally
            {
                reader.Close();
            }

            //Now use this geometry as the basis of our 2nd query

            MgFeatureQueryOptions parcelQuery = new MgFeatureQueryOptions();

            parcelQuery.SetFilter("RNAME LIKE 'SCHMITT%'");
            parcelQuery.SetSpatialFilter(parcels.GetFeatureGeometryName(), districtGeom, MgFeatureSpatialOperations.Inside);

            //Select the features
            reader = parcels.SelectFeatures(parcelQuery);

            MgSelectionBase selection = _viewer.GetSelection();

            try
            {
                selection.FromXml(""); //Clear existing selection data
                selection.AddFeatures(parcels, reader, 0);
            }
            finally
            {
                reader.Close();
            }

            //Because we manipulated the active selection outside the viewer
            //We need to call UpdateSelection() to instruct the viewer to
            //re-render the active selection. The "true" parameter instructs
            //the viewer to raise the SelectionChanged event as well, so that
            //subscribers like the Property Pane get updated as well.
            _viewer.UpdateSelection(true);
            _viewer.RefreshMap();
        }
示例#8
0
        private void btnQueryDistrict1_Click(object sender, EventArgs e)
        {
            MgMapBase         map       = _viewer.GetMap();
            MgLayerCollection layers    = map.GetLayers();
            MgLayerBase       districts = layers.GetItem("Districts");
            MgLayerBase       parcels   = layers.GetItem("Parcels");

            //Query the geometry of district 1
            MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();

            districtQuery.SetFilter("Autogenerated_SDF_ID = 1");

            MgFeatureReader   reader       = districts.SelectFeatures(districtQuery);
            MgGeometry        districtGeom = null;
            MgAgfReaderWriter agfRw        = new MgAgfReaderWriter();

            try
            {
                reader.ReadNext();
                MgByteReader geomAgf = reader.GetGeometry(districts.GetFeatureGeometryName());
                districtGeom = agfRw.Read(geomAgf);
            }
            finally
            {
                reader.Close();
            }

            //Now use this geometry as the basis of our 2nd query

            MgFeatureQueryOptions parcelQuery = new MgFeatureQueryOptions();

            parcelQuery.SetFilter("RNAME LIKE 'SCHMITT%'");
            parcelQuery.SetSpatialFilter(parcels.GetFeatureGeometryName(), districtGeom, MgFeatureSpatialOperations.Inside);

            //Select the features
            reader = parcels.SelectFeatures(parcelQuery);
            List <string> results = new List <string>();

            try
            {
                while (reader.ReadNext())
                {
                    if (!reader.IsNull("RPROPAD"))
                    {
                        results.Add(reader.GetString("RPROPAD"));
                    }
                }
            }
            finally
            {
                reader.Close();
            }

            new ParcelQueryResultWindow(results).ShowDialog();
        }
示例#9
0
        private void OnLineDigitized(double x1, double y1, double x2, double y2)
        {
            CheckRedlineLayer();
            MgCoordinateCollection coords = new MgCoordinateCollection();

            coords.Add(_geomFact.CreateCoordinateXY(x1, y1));
            coords.Add(_geomFact.CreateCoordinateXY(x2, y2));
            MgGeometry line = _geomFact.CreateLineString(coords);

            InsertRedlineGeometry(line);
        }
示例#10
0
        /// <summary>
        /// Установка зумирования и активной выборки (запуск через командную строку - отсюда название)
        /// </summary>
        /// <param name="sel_base">выборка, которую следует отобразить</param>
        internal static void ThroughAssZoomAndSelection(MgSelectionBase sel_base)
        {
            internal_saved_selection = AcMapFeatureEntityService.AddFeaturesToSelectionSet(null, sel_base);             // преобразование в SelectionSet и обратно,

            sel_base = AcMapFeatureEntityService.GetSelection(internal_saved_selection);                                // иначе дает сбой метод GetSelectedFeatures()

            MgEnvelope extents = new MgEnvelope();

            MgReadOnlyLayerCollection layers = sel_base.GetLayers();

            foreach (MgLayerBase layer in layers)
            {
                MgFeatureReader ftr_reader     = sel_base.GetSelectedFeatures(layer, layer.FeatureClassName, false);
                string          geom_prop_name = ftr_reader.GetClassDefinition().DefaultGeometryPropertyName;

                while (ftr_reader.ReadNext())
                {
                    MgByteReader      byte_reader       = ftr_reader.GetGeometry(geom_prop_name);
                    MgAgfReaderWriter agf_reader_writer = new MgAgfReaderWriter();
                    MgGeometry        curr_geom         = agf_reader_writer.Read(byte_reader);
                    extents.ExpandToInclude(curr_geom.Envelope());
                }
            }



            // зумирование и вызов функции выбора через командную строку

            Core.no_handle_selection = true;             // чтобы изменение выборки не обрабатывалось

            string zoom_str;

            if ((extents.Width == 0) && (extents.Width == extents.Height))
            {
                zoom_str = "'_zoom _c "
                           + extents.LowerLeftCoordinate.X.ToString() + "," + extents.LowerLeftCoordinate.Y.ToString() + " ";
            }
            else
            {
                zoom_str = "'_zoom _w "
                           + (extents.LowerLeftCoordinate.X - extents.Width / 2).ToString()
                           + ","
                           + (extents.LowerLeftCoordinate.Y - extents.Height / 2).ToString()
                           + " "
                           + (extents.UpperRightCoordinate.X + extents.Width / 2).ToString()
                           + ","
                           + (extents.UpperRightCoordinate.Y + extents.Height / 2).ToString();
            }


            Core.SendStringToExecute(zoom_str + "\n"
                                     + "ThroughAssZoomAndSelectionHelperFunction\n"
                                     , true, false, false);
        }
示例#11
0
        // GET: Search/Results
        public ActionResult Results(SearchInputModel input)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgLayerCollection layers = map.GetLayers();
            int lidx = layers.IndexOf("Parcels");

            if (lidx < 0)
            {
                throw new Exception("Layer not found on map: Parcels");
            }
            MgLayerBase           layer = layers[lidx];
            MgFeatureQueryOptions query = new MgFeatureQueryOptions();

            //Don't fret about the input here. This is not a SQL injection attack vector. This filter string is
            //not SQL, it's a FDO filter. A 'DROP TABLE' or any other destructive SQL will fail on
            //query execution when this filter is parsed to a FDO filter.
            switch (input.By)
            {
            case "OWNER":
                query.SetFilter("RNAME LIKE '%" + input.Query.Replace("'", "\'") + "%'");
                break;

            case "ADDRESS":
                query.SetFilter("RPROPAD LIKE '%" + input.Query.Replace("'", "\'") + "%'");
                break;

            case "BBOX":
                double[] parts = input.Query.Split(',').Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
                if (parts.Length != 4)
                {
                    throw new Exception("Invalid BBOX parameter");
                }
                MgWktReaderWriter wktRw      = new MgWktReaderWriter();
                MgGeometry        filterGeom = wktRw.Read(MakeWktPolygon(parts[0], parts[1], parts[2], parts[3]));
                query.SetSpatialFilter(layer.FeatureGeometryName, filterGeom, MgFeatureSpatialOperations.Intersects);
                break;

            default:
                throw new Exception("Unknown query type: " + input.By);
            }

            SearchResultViewModel vm = new SearchResultViewModel();

            vm.Session = input.Session;
            vm.MapName = input.MapName;
            vm.LoadResults(layer, query);
            return(View(vm));
        }
示例#12
0
        void OnSelectRadius(object sender, EventArgs e)
        {
            if (_viewer == null)
            {
                return;
            }

            _viewer.DigitizeCircle((x, y, r) =>
            {
                MgGeometry geom = _wktRw.Read(Util.MakeWktCircle(x, y, r, true));
                _viewer.SelectByGeometry(geom);
            });
        }
示例#13
0
 private void AddRectangle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeRectangle((x1, y1, x2, y2) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgGeometry geom = _wktRW.Read(Util.MakeWktPolygon(x1, y1, x2, y2));
         InsertRedlineGeometry(text, geom, onRedlineAdded);
     });
 }
示例#14
0
 private void AddCircle(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeCircle((x, y, r) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgGeometry geom = _wktRW.Read(Util.MakeWktCircle(x, y, r, true));
         InsertRedlineGeometry(text, geom, onRedlineAdded);
     });
 }
示例#15
0
        private void OnLineStringDigitized(double[,] coordinates)
        {
            CheckRedlineLayer();
            MgCoordinateCollection coords = new MgCoordinateCollection();

            for (int i = 0; i < coordinates.GetLength(0); i++)
            {
                coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
            }
            MgGeometry line = _geomFact.CreateLineString(coords);

            InsertRedlineGeometry(line);
        }
示例#16
0
 public void EmitGeometry(MgGeometry geo, int extrude, double ht)
 {
     if (geo != null)
     {
         if (geo.GetGeometryType() == MgGeometryType.Polygon)
         {
             EmitPolygon(geo, extrude, ht);
         }
         else if (geo.GetGeometryType() == MgGeometryType.MultiPolygon)
         {
             EmitMultiPolygon(geo, extrude, ht);
         }
     }
 }
示例#17
0
 private void AddPoint(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizePoint((x, y) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinate coord = _geomFact.CreateCoordinateXY(x, y);
         MgGeometry point   = _geomFact.CreatePoint(coord);
         InsertRedlineGeometry(text, point, onRedlineAdded);
     });
 }
示例#18
0
        private void OnPolygonDigitized(double[,] coordinates)
        {
            CheckRedlineLayer();
            MgCoordinateCollection coords = new MgCoordinateCollection();

            for (int i = 0; i < coordinates.GetLength(0); i++)
            {
                coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
            }
            coords.Add(_geomFact.CreateCoordinateXY(coordinates[0, 0], coordinates[0, 1]));
            MgLinearRing ring = _geomFact.CreateLinearRing(coords);
            MgGeometry   poly = _geomFact.CreatePolygon(ring, null);

            InsertRedlineGeometry(poly);
        }
示例#19
0
        MgPropertyCollection MakePoint(String name, double x, double y, MgWktReaderWriter wktReaderWriter, MgAgfReaderWriter agfReaderWriter)
        {
            MgPropertyCollection propertyCollection = new MgPropertyCollection();
            MgStringProperty     nameProperty       = new MgStringProperty("NAME", name);

            propertyCollection.Add(nameProperty);

            MgGeometry         geometry           = wktReaderWriter.Read("POINT XY (" + x + " " + y + ")");
            MgByteReader       geometryByteReader = agfReaderWriter.Write(geometry);
            MgGeometryProperty geometryProperty   = new MgGeometryProperty("GEOM", geometryByteReader);

            propertyCollection.Add(geometryProperty);

            return(propertyCollection);
        }
示例#20
0
        public override void Invoke()
        {
            var viewer = this.Viewer;

            viewer.DigitizeCircle((x, y, r) =>
            {
                if (_wktRw == null)
                {
                    _wktRw = new MgWktReaderWriter();
                }

                MgGeometry geom = _wktRw.Read(Util.MakeWktCircle(x, y, r, true));
                viewer.SelectByGeometry(geom);
            });
        }
示例#21
0
文件: MainForm.cs 项目: achilex/MgDev
 private void btnSelectPolygon_Click(object sender, EventArgs e)
 {
     mgMapViewer1.DigitizePolygon((coordinates) =>
     {
         MgCoordinateCollection coords = new MgCoordinateCollection();
         for (int i = 0; i < coordinates.GetLength(0); i++)
         {
             coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
         }
         coords.Add(_geomFact.CreateCoordinateXY(coordinates[0, 0], coordinates[0, 1]));
         MgLinearRing ring = _geomFact.CreateLinearRing(coords);
         MgGeometry poly   = _geomFact.CreatePolygon(ring, null);
         mgMapViewer1.SelectByGeometry(poly);
     });
 }
示例#22
0
 private void btnPolygon_Click(object sender, EventArgs e)
 {
     _viewer.DigitizePolygon((coordinates) =>
     {
         ClearFilterGeometry();
         MgCoordinateCollection coords = new MgCoordinateCollection();
         for (int i = 0; i < coordinates.GetLength(0); i++)
         {
             coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
         }
         coords.Add(_geomFact.CreateCoordinateXY(coordinates[0, 0], coordinates[0, 1]));
         MgLinearRing ring = _geomFact.CreateLinearRing(coords);
         _filterGeometry   = _geomFact.CreatePolygon(ring, null);
         lblSpatialFilterGeomSet.Visible = true;
     });
 }
示例#23
0
 private void AddLine(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeLine((x1, y1, x2, y2) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinateCollection coords = new MgCoordinateCollection();
         coords.Add(_geomFact.CreateCoordinateXY(x1, y1));
         coords.Add(_geomFact.CreateCoordinateXY(x2, y2));
         MgGeometry line = _geomFact.CreateLineString(coords);
         InsertRedlineGeometry(text, line, onRedlineAdded);
     });
 }
示例#24
0
 private void AddLineString(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizeLineString((coordinates) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinateCollection coords = new MgCoordinateCollection();
         for (int i = 0; i < coordinates.GetLength(0); i++)
         {
             coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
         }
         MgGeometry line = _geomFact.CreateLineString(coords);
         InsertRedlineGeometry(text, line, onRedlineAdded);
     });
 }
示例#25
0
        void OnSelectPolygon(object sender, EventArgs e)
        {
            if (_viewer == null)
            {
                return;
            }

            _viewer.DigitizePolygon((coordinates) => {
                MgCoordinateCollection coords = new MgCoordinateCollection();
                for (int i = 0; i < coordinates.GetLength(0); i++)
                {
                    coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
                }
                coords.Add(_geomFact.CreateCoordinateXY(coordinates[0, 0], coordinates[0, 1]));
                MgLinearRing ring = _geomFact.CreateLinearRing(coords);
                MgGeometry poly   = _geomFact.CreatePolygon(ring, null);
                _viewer.SelectByGeometry(poly);
            });
        }
示例#26
0
        private void OnPointDrawn(double x, double y)
        {
            if (_pointLayer == null) //Our point layer doesn't exist
            {
                CreateRedlineLayer();
            }

            //Now insert our point. This code should look familiar
            //to you, setting up the MgPropertyCollection for insertion
            MgPropertyCollection props = new MgPropertyCollection();
            MgWktReaderWriter    wktRw = new MgWktReaderWriter();
            MgAgfReaderWriter    agfRw = new MgAgfReaderWriter();

            MgGeometry   geom = wktRw.Read("POINT (" + x + " " + y + ")");
            MgByteReader agf  = agfRw.Write(geom);

            MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf);

            props.Add(geomProp);

            //Here's where we differ from the official MapGuide API
            //instead of a monolithic UpdateFeatures() that tries to
            //do everything, we have individual InsertFeatures/DeleteFeatures/UpdateFeatures
            //methods. So here's the mg-desktop way

            MgFeatureReader result = _pointLayer.InsertFeatures(props);

            result.Close();

            //Or if you have have access to the MgdLayer instance

            /*
             * MgResourceIdentifier fsId = new MgResourceIdentifier(_pointLayer.GetFeatureSourceId());
             * MgServiceFactory factory = new MgServiceFactory();
             * MgdFeatureService featSvc = (MgdFeatureService)factory.CreateService(MgServiceType.FeatureService);
             * MgFeatureReader fr = featSvc.InsertFeatures(fsId, "Default:Redline", props);
             * fr.Close();
             */

            //Now refresh to see your newly drawn point
            mgMapViewer1.RefreshMap();
        }
示例#27
0
        public override void Invoke()
        {
            var viewer = this.Viewer;

            viewer.DigitizePolygon((coordinates) =>
            {
                if (_geomFact == null)
                {
                    _geomFact = new MgGeometryFactory();
                }

                MgCoordinateCollection coords = new MgCoordinateCollection();
                for (int i = 0; i < coordinates.GetLength(0); i++)
                {
                    coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
                }
                coords.Add(_geomFact.CreateCoordinateXY(coordinates[0, 0], coordinates[0, 1]));
                MgLinearRing ring = _geomFact.CreateLinearRing(coords);
                MgGeometry poly   = _geomFact.CreatePolygon(ring, null);
                viewer.SelectByGeometry(poly);
            });
        }
示例#28
0
        private void InsertRedlineGeometry(MgGeometry geom)
        {
            MgPropertyCollection feature = new MgPropertyCollection();
            MgByteReader agf = _agfRW.Write(geom);
            MgGeometryProperty geomProp = new MgGeometryProperty("Geometry", agf);
            feature.Add(geomProp);

            _redlineLayer.ForceRefresh();
            var reader = _redlineLayer.InsertFeatures(feature);
            int inserted = 0;
            while (reader.ReadNext())
            {
                inserted++;
            }
            reader.Close();
            if (inserted > 0)
            {
                _viewer.RefreshMap();
                IMapLegend legend = Shell.Instance.Legend;
                if (legend != null)
                    legend.RefreshLegend();
            }
        }
示例#29
0
        public void LoadResults(MgLayerBase layer, MgFeatureQueryOptions query)
        {
            MgClassDefinition clsDef = layer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = clsDef.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps[0];
            string idPropName = idProp.Name;
            string geomName   = layer.FeatureGeometryName;

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

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

                        res.X = coord.X;
                        res.Y = coord.Y;
                    }
                    this.Results.Add(res);
                }
            }
            finally
            {
                reader.Close();
            }
        }
示例#30
0
 public override MgQueryMapFeaturesResult QueryMapFeatures(MgQueryRequestType queryType, MgStringCollection layerNames, MgGeometry filterGeom, int selectionVariant, string featureFilter, int maxFeatures, int layerAttributeFilter)
 {
     var fi = _renderSvc.QueryFeatures(_implMap, layerNames, filterGeom, selectionVariant, featureFilter, maxFeatures, layerAttributeFilter);
     try
     {
         if (queryType == MgQueryRequestType.Tooltip)
             return MakeTooltip(fi.GetTooltip());
         else
             return MakeSelectionResult(fi.GetSelection());
     }
     finally
     {
         fi.Dispose();
     }
 }
示例#31
0
    private void EmitPolygon(MgGeometry geo, int extrude, double ht)
    {
        if (geo != null)
        {
            outString.Append("<Polygon>");
            outString.Append("<extrude>" + extrude + "</extrude>");
            outString.Append("<altitudeMode>relativeToGround</altitudeMode>");
            outString.Append("<outerBoundaryIs>");

            MgPolygon polygon = (MgPolygon)geo;
            EmitLinearRing(polygon.GetExteriorRing(), ht);
            outString.Append("</outerBoundaryIs>");
            outString.Append("</Polygon>");
        }
    }
示例#32
0
 public void WriteConsolidatedGeometryRing(MgGeometry geo, int extrude, double ht)
 {
     EmitPolygon(geo, extrude, ht);
 }
示例#33
0
文件: Util.cs 项目: kanbang/Colt
 public static void AddFeatureToCollection(MgBatchPropertyCollection propCollection, MgAgfReaderWriter agfRW, int featureId, MgGeometry featureGeom)
 {
     MgPropertyCollection bufferProps = new MgPropertyCollection();
     MgInt32Property idProp = new MgInt32Property("ID", featureId); //NOXLATE
     bufferProps.Add(idProp);
     MgByteReader geomReader = agfRW.Write(featureGeom);
     MgGeometryProperty geomProp = new MgGeometryProperty("GEOM", geomReader); //NOXLATE
     bufferProps.Add(geomProp);
     propCollection.Add(bufferProps);
 }
示例#34
0
 private void btnPolygon_Click(object sender, EventArgs e)
 {
     _viewer.DigitizePolygon((coordinates) =>
     {
         ClearFilterGeometry();
         MgCoordinateCollection coords = new MgCoordinateCollection();
         for (int i = 0; i < coordinates.GetLength(0); i++)
         {
             coords.Add(_geomFact.CreateCoordinateXY(coordinates[i, 0], coordinates[i, 1]));
         }
         coords.Add(_geomFact.CreateCoordinateXY(coordinates[0, 0], coordinates[0, 1]));
         MgLinearRing ring = _geomFact.CreateLinearRing(coords);
         _filterGeometry = _geomFact.CreatePolygon(ring, null);
         lblSpatialFilterGeomSet.Visible = true;
     });
 }
示例#35
0
 /// <summary>
 /// Selects features from all selectable layers that intersects the given geometry
 /// </summary>
 /// <param name="geom"></param>
 public void SelectByGeometry(MgGeometry geom)
 {
     SelectByGeometry(geom, -1);
 }
示例#36
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());
            }
        }
示例#37
0
 public static string GetWkt(MgGeometry geom)
 {
     return(_wktRw.Write(geom));
 }
示例#38
0
        public static MgByteReader GetAgf(IGeometry geom)
        {
            MgGeometry mgeom = _wktRw.Read(geom.AsText());

            return(_agfRw.Write(mgeom));
        }
示例#39
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="queryType"></param>
 /// <param name="layerNames"></param>
 /// <param name="filterGeom"></param>
 /// <param name="selectionVariant"></param>
 /// <param name="featureFilter"></param>
 /// <param name="maxFeatures"></param>
 /// <param name="layerAttributeFilter"></param>
 /// <returns></returns>
 public abstract MgQueryMapFeaturesResult QueryMapFeatures(MgQueryRequestType queryType, MgStringCollection layerNames, MgGeometry filterGeom, int selectionVariant, string featureFilter, int maxFeatures, int layerAttributeFilter);
示例#40
0
 /// <summary>
 /// Selects features from all selectable layers that intersects the given geometry
 /// </summary>
 /// <param name="geom"></param>
 /// <param name="maxFeatures"></param>
 public void SelectByGeometry(MgGeometry geom, int maxFeatures)
 {
     SelectByGeometry(geom, maxFeatures, null);
 }
示例#41
0
        /// <summary>
        /// Selects features from all selectable layers that intersects the given geometry
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="maxFeatures"></param>
        /// <param name="selectionHandler"></param>
        public void SelectByGeometry(MgGeometry geom, int maxFeatures, Action<MgSelectionBase> selectionHandler)
        {
            //Don't select if dragging. This is the cause of the failure to render
            //multiple selections, which required a manual refresh afterwards
            if (isDragging)
                return;
#if TRACE
            var sw = new Stopwatch();
            sw.Start();
#endif
            MgSelectionBase newSel = null;
            //We will be either wiping or updating the existing selection set
            MgSelectionQueryResult sel = _provider.QueryMapFeatures(MgQueryRequestType.Selection, null, geom, MgFeatureSpatialOperations.Intersects, "", maxFeatures, (1 | 2)) as MgSelectionQueryResult; //1=Visible, 2=Selectable, 4=HasTooltips
            if (sel != null)
            {
                newSel = sel.Selection;
                string newXml = newSel.ToXml();
                _selection.FromXml(newXml);

                //If specified, we need to retain this for passing to the given selection handler
                if (selectionHandler == null)
                    newSel.Dispose();
            }
            else
            {
                _selection.FromXml(string.Empty);
            }
#if TRACE
            sw.Stop();
            //Trace.TraceInformation("Selection processing completed in {0}ms", sw.ElapsedMilliseconds);
#endif
            //This selection may result in nothing, so we invalidate the selection image beforehand
            if (_selectionImage != null)
            {
                _selectionImage.Dispose();
                _selectionImage = null;
            }
            RenderSelection(true); //This is either async or queued up. Either way do this before firing off selection changed
            if (selectionHandler == null)
            {
                var handler = this.SelectionChanged;
                if (handler != null)
                    handler(this, EventArgs.Empty);
            }
            else
            {
                selectionHandler(newSel);
            }
        }
示例#42
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());
            }
        }
示例#43
0
 private void EmitMultiPolygon(MgGeometry geo, int extrude, double ht)
 {
     if (geo != null)
     {
         outString.Append("<GeometryCollection>");
         MgMultiPolygon multiPolygon = (MgMultiPolygon)geo;
         for (int i = 0; i < multiPolygon.GetCount(); i++)
         {
             EmitPolygon(multiPolygon.GetPolygon(i), extrude, ht);
         }
         outString.Append("</GeometryCollection>");
     }
 }
示例#44
0
 private void btnRectangle_Click(object sender, EventArgs e)
 {
     _viewer.DigitizeRectangle((llx, lly, urx, ury) =>
     {
         ClearFilterGeometry();
         _filterGeometry = _wktRw.Read(Util.MakeWktPolygon(llx, lly, urx, ury));
         lblSpatialFilterGeomSet.Visible = true;
     });
 }