Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        private void btnCreateBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase           selection = _viewer.GetSelection();
            MgReadOnlyLayerCollection layers    = selection.GetLayers();

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

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

            int bufferRingSize  = 100; // measured in metres
            int bufferRingCount = 5;

            // Set up some objects for coordinate conversion
            MgMapBase           map             = _viewer.GetMap();
            MgLayerCollection   mapLayers       = map.GetLayers();
            MgMapViewerProvider provider        = _viewer.GetProvider();
            MgResourceService   resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);

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

            BufferHelper helper = new BufferHelper();

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

            MgdLayer bufferLayer = null;
            int      layerIndex  = mapLayers.IndexOf("Buffer");

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

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

            // Get the selected features from the MgSelection object
            MgFeatureReader featureReader = selection.GetSelectedFeatures(parcels, parcels.GetFeatureClassName(), false);

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

            MgGeometryCollection inputGeometries = new MgGeometryCollection();

            while (featureReader.ReadNext())
            {
                MgByteReader featureGeometryData = featureReader.GetGeometry(parcels.GetFeatureGeometryName());
                MgGeometry   featureGeometry     = agfReaderWriter.Read(featureGeometryData);

                inputGeometries.Add(featureGeometry);
            }

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

            // Add buffer features to the temporary feature source.
            // Create multiple concentric buffers to show area.
            // If the stylization for the layer draws the features
            // partially transparent, the concentric rings will be
            // progressively darker towards the center.
            // The stylization is set in the layer template file, which
            // is used in function CreateBufferLayer().

            for (int bufferRing = 0; bufferRing < bufferRingCount; bufferRing++)
            {
                double     bufferDist     = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize * (bufferRing + 1));
                MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                MgPropertyCollection properties = new MgPropertyCollection();
                properties.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));

                MgFeatureReader fr = bufferLayer.InsertFeatures(properties);
                fr.Close();
            }

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

            MessageBox.Show("Buffer created");
            _viewer.RefreshMap();
            IMapLegend legend = Shell.Instance.Legend;

            if (legend != null)
            {
                legend.RefreshLegend();
            }
        }
Exemplo n.º 6
0
        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();
                    }
                }
            }
        }
Exemplo n.º 7
0
        private MgFeature CreateFeatureFromReader(MgFeatureReader reader)
        {
            var feature = new MgFeature();
            var hash = feature.Properties;
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                var pt = reader.GetPropertyType(i);
                //Skip un-presentable types
                if (pt == MgPropertyType.Null ||
                    pt == MgPropertyType.Raster ||
                    pt == MgPropertyType.Blob ||
                    pt == MgPropertyType.Feature ||
                    pt == MgPropertyType.Clob)
                    continue;

                string name = reader.GetPropertyName(i);

                if (reader.IsNull(i))
                {
                    hash[name] = null;
                }
                else
                {
                    switch (pt)
                    {
                        case MgPropertyType.Boolean:
                            hash[name] = reader.GetBoolean(i);
                            break;
                        case MgPropertyType.Byte:
                            hash[name] = reader.GetByte(i);
                            break;
                        case MgPropertyType.DateTime:
                            {
                                var dt = reader.GetDateTime(i);
                                hash[name] = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0);
                            }
                            break;
                        case MgPropertyType.Double:
                        case MgPropertyType.Decimal:
                            hash[name] = reader.GetDouble(i);
                            break;
                        case MgPropertyType.Int16:
                            hash[name] = reader.GetInt16(i);
                            break;
                        case MgPropertyType.Int32:
                            hash[name] = reader.GetInt32(i);
                            break;
                        case MgPropertyType.Int64:
                            hash[name] = reader.GetInt64(i);
                            break;
                        case MgPropertyType.Single:
                            hash[name] = reader.GetSingle(i);
                            break;
                        case MgPropertyType.String:
                            hash[name] = reader.GetString(i);
                            break;
                        case MgPropertyType.Geometry:
                            {
                                MgByteReader agf = reader.GetGeometry(i);
                                feature.Geometry = _agfRw.Read(agf);
                            }
                            break;
                    }
                }
            }
            return feature;
        }
Exemplo n.º 8
0
        /// <summary>Получает набор свойств MgPropertyCollection из текущей записи _reader в соответствии со списком _listed_prop_defs</summary>
        /// <param name="_reader"></param>
        /// <param name="_listed_prop_defs"></param>
        /// <returns></returns>
        internal static MgPropertyCollection GetPropertiesFromReader(MgFeatureReader _reader, MgPropertyDefinitionCollection _listed_prop_defs)
        {
            MgPropertyCollection result_props = new MgPropertyCollection();

            MgPropertyDefinitionCollection reader_prop_defs = _reader.GetClassDefinition().GetProperties();

            foreach (MgPropertyDefinition curr_prop_def in _listed_prop_defs)
            {
                if (!reader_prop_defs.Contains(curr_prop_def.Name) || _reader.IsNull(curr_prop_def.Name))
                {
                    continue;
                }

                int property_type = _reader.GetPropertyType(curr_prop_def.Name);
                if (property_type == MgPropertyType.Blob)
                {
                    result_props.Add(
                        new MgBlobProperty(curr_prop_def.Name, _reader.GetBLOB(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Boolean)
                {
                    result_props.Add(
                        new MgBooleanProperty(curr_prop_def.Name, _reader.GetBoolean(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Byte)
                {
                    result_props.Add(
                        new MgByteProperty(curr_prop_def.Name, _reader.GetByte(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Clob)
                {
                    result_props.Add(
                        new MgClobProperty(curr_prop_def.Name, _reader.GetCLOB(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.DateTime)
                {
                    result_props.Add(
                        new MgDateTimeProperty(curr_prop_def.Name, _reader.GetDateTime(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Double)
                {
                    result_props.Add(
                        new MgDoubleProperty(curr_prop_def.Name, _reader.GetDouble(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Feature)
                {
                    result_props.Add(
                        new MgFeatureProperty(curr_prop_def.Name, _reader.GetFeatureObject(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Geometry)
                {
                    result_props.Add(
                        new MgGeometryProperty(curr_prop_def.Name, _reader.GetGeometry(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Int16)
                {
                    result_props.Add(
                        new MgInt16Property(curr_prop_def.Name, _reader.GetInt16(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Int32)
                {
                    result_props.Add(
                        new MgInt32Property(curr_prop_def.Name, _reader.GetInt32(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Int64)
                {
                    result_props.Add(
                        new MgInt64Property(curr_prop_def.Name, _reader.GetInt64(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Raster)
                {
                    result_props.Add(
                        new MgRasterProperty(curr_prop_def.Name, _reader.GetRaster(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.Single)
                {
                    result_props.Add(
                        new MgSingleProperty(curr_prop_def.Name, _reader.GetSingle(curr_prop_def.Name))
                        );
                }
                else if (property_type == MgPropertyType.String)
                {
                    result_props.Add(
                        new MgStringProperty(curr_prop_def.Name, _reader.GetString(curr_prop_def.Name))
                        );
                }
            }              //foreach

            return(result_props);
        }
        public LocalNativeFeature(MgFeatureReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
            : base(Utility.ConvertClassDefinition(reader.GetClassDefinition()))
        {
            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                string name = _ordinalMap[i];
                GetByteReaderMethod getblob = () => { return(reader.GetBLOB(name)); };
                GetByteReaderMethod getclob = () => { return(reader.GetCLOB(name)); };
                GetByteReaderMethod getgeom = () => { return(reader.GetGeometry(name)); };
                if (!reader.IsNull(name))
                {
                    var pt = (PropertyValueType)reader.GetPropertyType(name);
                    switch (pt)
                    {
                    case PropertyValueType.Blob:
                        ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                        break;

                    case PropertyValueType.Boolean:
                        ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                        break;

                    case PropertyValueType.Byte:
                        ((ByteValue)_values[name]).Value = reader.GetByte(name);
                        break;

                    case PropertyValueType.Clob:
                        byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                        ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                        break;

                    case PropertyValueType.DateTime:
                        ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                        break;

                    case PropertyValueType.Double:
                        ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                        break;

                    case PropertyValueType.Feature:
                        ((FeatureValue)_values[name]).Value = GetFeatureArray(reader, name);
                        break;

                    case PropertyValueType.Geometry:
                        //TODO: See if SWIG issues come into play here
                        try
                        {
                            //TODO: See if SWIG issues come into play here
                            var geom = agfRw.Read(reader.GetGeometry(name));
                            var wkt  = wktRw.Write(geom);
                            ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                        }
                        catch     //Invalid geometry fail!
                        {
                            ((GeometryValue)_values[name]).SetNull();
                        }
                        break;

                    case PropertyValueType.Int16:
                        ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                        break;

                    case PropertyValueType.Int32:
                        ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                        break;

                    case PropertyValueType.Int64:
                        ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                        break;

                    case PropertyValueType.Single:
                        ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                        break;

                    case PropertyValueType.String:
                        ((StringValue)_values[name]).Value = reader.GetString(name);
                        break;
                    }
                }
            }
        }
Exemplo n.º 10
0
 public LocalNativeFeature(MgFeatureReader reader, FixedWKTReader mgReader, MgAgfReaderWriter agfRw, MgWktReaderWriter wktRw)
     : base(Utility.ConvertClassDefinition(reader.GetClassDefinition()))
 {
     for (int i = 0; i < reader.GetPropertyCount(); i++)
     {
         string name = _ordinalMap[i];
         GetByteReaderMethod getblob = () => { return reader.GetBLOB(name); };
         GetByteReaderMethod getclob = () => { return reader.GetCLOB(name); };
         GetByteReaderMethod getgeom = () => { return reader.GetGeometry(name); };
         if (!reader.IsNull(name))
         {
             var pt = (PropertyValueType)reader.GetPropertyType(name);
             switch (pt)
             {
                 case PropertyValueType.Blob:
                     ((BlobValue)_values[name]).Value = Utility.StreamAsArray(new MgReadOnlyStream(getblob));
                     break;
                 case PropertyValueType.Boolean:
                     ((BooleanValue)_values[name]).Value = reader.GetBoolean(name);
                     break;
                 case PropertyValueType.Byte:
                     ((ByteValue)_values[name]).Value = reader.GetByte(name);
                     break;
                 case PropertyValueType.Clob:
                     byte[] b = Utility.StreamAsArray(new MgReadOnlyStream(getclob));
                     ((ClobValue)_values[name]).Value = Encoding.UTF8.GetChars(b);
                     break;
                 case PropertyValueType.DateTime:
                     ((DateTimeValue)_values[name]).Value = Utility.ConvertMgDateTime(reader.GetDateTime(name));
                     break;
                 case PropertyValueType.Double:
                     ((DoubleValue)_values[name]).Value = reader.GetDouble(name);
                     break;
                 case PropertyValueType.Feature:
                     ((FeatureValue)_values[name]).Value = GetFeatureArray(reader, name);
                     break;
                 case PropertyValueType.Geometry:
                     //TODO: See if SWIG issues come into play here
                     try
                     {
                         //TODO: See if SWIG issues come into play here
                         var geom = agfRw.Read(reader.GetGeometry(name));
                         var wkt = wktRw.Write(geom);
                         ((GeometryValue)_values[name]).Value = mgReader.Read(wkt);
                     }
                     catch //Invalid geometry fail!
                     {
                         ((GeometryValue)_values[name]).SetNull();
                     }
                     break;
                 case PropertyValueType.Int16:
                     ((Int16Value)_values[name]).Value = reader.GetInt16(name);
                     break;
                 case PropertyValueType.Int32:
                     ((Int32Value)_values[name]).Value = reader.GetInt32(name);
                     break;
                 case PropertyValueType.Int64:
                     ((Int64Value)_values[name]).Value = reader.GetInt64(name);
                     break;
                 case PropertyValueType.Single:
                     ((SingleValue)_values[name]).Value = reader.GetSingle(name);
                     break;
                 case PropertyValueType.String:
                     ((StringValue)_values[name]).Value = reader.GetString(name);
                     break;
             }
         }
     }
 }
Exemplo n.º 11
0
 //---------------------------------------------------------------------------------------
 //
 //        ���ܣ�δ֪��ѯ����е��������ݵ����͵Ĵ������
 //
 //
 //         ���ߣ�
 //
 //         ���ڣ� 2007.5.23
 //        
 //         �޸���ʷ����
 //        
 //---------------------------------------------------------------------------------------
 public void GetPropertyValue(MgFeatureReader featureReader, int propertyType, string propertyName)
 {
     switch (propertyType )
        {
            case MgPropertyType.Null:
                break;
            case MgPropertyType.Boolean:
                bool val1 = featureReader.GetBoolean(propertyName);
                break;
            case MgPropertyType.Byte:
                Byte val2 = featureReader.GetByte(propertyName);
                break;
            case MgPropertyType.DateTime:
                MgDateTime val3 = featureReader.GetDateTime(propertyName);
                break;
            case MgPropertyType.Single:
                float val4 = featureReader.GetSingle(propertyName);
                break;
            case MgPropertyType.Double:
                double val5 = featureReader.GetDouble(propertyName);
                break;
            case MgPropertyType.Int16:
                Int16 val6 = featureReader.GetInt16(propertyName);
                break;
            case MgPropertyType.Int32:
                Int32 val7 = featureReader.GetInt32(propertyName);
                break;
            case MgPropertyType.Int64:
                Int64 val8 = featureReader.GetInt64(propertyName);
                break;
            case MgPropertyType.String:
                string val9 = featureReader.GetString(propertyName);
                break;
            case MgPropertyType.Blob:
                string val10 = propertyName + " ��Blob����";
                break;
            case MgPropertyType.Clob:
                string val11 = propertyName + " ��Clob����";
                break;
            case MgPropertyType.Feature:
                MgFeatureReader val12 = featureReader.GetFeatureObject(propertyName);
                break;
            case MgPropertyType.Geometry:
                MgByteReader va13l = featureReader.GetGeometry(propertyName);
                MgAgfReaderWriter agfReader = new MgAgfReaderWriter();
                MgGeometry districtGeometry = agfReader.Read(va13l);
                break;
            case MgPropertyType.Raster:
                MgRaster val14 = featureReader.GetRaster(propertyName) ;
                break;
            default:
                string val13 =  "δ֪����";
                break;
        }
 }
Exemplo n.º 12
0
        private MgFeature CreateFeatureFromReader(MgFeatureReader reader)
        {
            var feature = new MgFeature();
            var hash    = feature.Properties;

            for (int i = 0; i < reader.GetPropertyCount(); i++)
            {
                var pt = reader.GetPropertyType(i);
                //Skip un-presentable types
                if (pt == MgPropertyType.Null ||
                    pt == MgPropertyType.Raster ||
                    pt == MgPropertyType.Blob ||
                    pt == MgPropertyType.Feature ||
                    pt == MgPropertyType.Clob)
                {
                    continue;
                }

                string name = reader.GetPropertyName(i);

                if (reader.IsNull(i))
                {
                    hash[name] = null;
                }
                else
                {
                    switch (pt)
                    {
                    case MgPropertyType.Boolean:
                        hash[name] = reader.GetBoolean(i);
                        break;

                    case MgPropertyType.Byte:
                        hash[name] = reader.GetByte(i);
                        break;

                    case MgPropertyType.DateTime:
                    {
                        var dt = reader.GetDateTime(i);
                        hash[name] = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0);
                    }
                    break;

                    case MgPropertyType.Double:
                    case MgPropertyType.Decimal:
                        hash[name] = reader.GetDouble(i);
                        break;

                    case MgPropertyType.Int16:
                        hash[name] = reader.GetInt16(i);
                        break;

                    case MgPropertyType.Int32:
                        hash[name] = reader.GetInt32(i);
                        break;

                    case MgPropertyType.Int64:
                        hash[name] = reader.GetInt64(i);
                        break;

                    case MgPropertyType.Single:
                        hash[name] = reader.GetSingle(i);
                        break;

                    case MgPropertyType.String:
                        hash[name] = reader.GetString(i);
                        break;

                    case MgPropertyType.Geometry:
                    {
                        MgByteReader agf = reader.GetGeometry(i);
                        feature.Geometry = _agfRw.Read(agf);
                    }
                    break;
                    }
                }
            }
            return(feature);
        }
Exemplo n.º 13
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            btnCreate.Enabled = false;
            try
            {
                var layerName = txtBufferLayer.Text.Trim();
                if (string.IsNullOrEmpty(layerName))
                {
                    MessageBox.Show(Strings.MsgEnterNameForLayer);
                    return;
                }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                MgBatchPropertyCollection propCollection = new MgBatchPropertyCollection();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        features.Close();
                    }
                }

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

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

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

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

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

                //build report message
                if (newBuffer)
                {
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerCreated, txtBufferLayer.Text));
                }
                else
                {
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerUpdated, txtBufferLayer.Text));
                }
            }
            finally
            {
                btnCreate.Enabled = true;
            }
        }
Exemplo n.º 14
0
    MgGeometry MultiGeometryFromSelection(MgFeatureService featureSrvc, MgMap map, String selText)
    {
        MgSelection sel = new MgSelection(map);

        sel.FromXml(selText);
        MgReadOnlyLayerCollection selLayers = sel.GetLayers();

        if (selLayers == null)
        {
            return(null);
        }
        MgGeometryCollection geomColl = new MgGeometryCollection();
        MgAgfReaderWriter    agfRW    = new MgAgfReaderWriter();
        bool polyOnly = true;

        for (int i = 0; i < selLayers.GetCount(); i++)
        {
            MgLayer layer = (MgLayer)selLayers.GetItem(i);

            // TODO:  How to get selectionSize?
            //int selectionSize = 20;
            string filter = sel.GenerateFilter(layer, layer.GetFeatureClassName());

            if (filter == "")
            {
                continue;
            }

            MgFeatureQueryOptions query = new MgFeatureQueryOptions();
            query.SetFilter(filter);
            MgResourceIdentifier featureSource = new MgResourceIdentifier(layer.GetFeatureSourceId());
            MgFeatureReader      features      = featureSrvc.SelectFeatures(featureSource, layer.GetFeatureClassName(), query);

            if (features != null)
            {
                MgClassDefinition classDef     = features.GetClassDefinition();
                String            geomPropName = classDef.GetDefaultGeometryPropertyName();
                int j = 0;
                //bool isPoly = true;
                while (features.ReadNext())
                {
                    MgByteReader geomReader = features.GetGeometry(geomPropName);
                    MgGeometry   geom       = agfRW.Read(geomReader);
                    if (j++ == 0)
                    {
                        int type = geom.GetGeometryType();
                        if (type == MgGeometryType.MultiPolygon || type == MgGeometryType.CurvePolygon || type == MgGeometryType.MultiCurvePolygon)
                        {
                            //isPoly = false;
                            polyOnly = false;
                        }
                        else if (type != MgGeometryType.Polygon)
                        {
                            break;
                        }
                    }
                    geomColl.Add(geom);
                }
                features.Close();
                features.Dispose();
            }
        }

        if (geomColl.GetCount() == 0)
        {
            return(null);
        }

        MgGeometryFactory gf = new MgGeometryFactory();

        if (polyOnly)
        {
            MgPolygonCollection polyColl = new MgPolygonCollection();
            for (int j = 0; j < geomColl.GetCount(); j++)
            {
                polyColl.Add((MgPolygon)geomColl.GetItem(j));
            }
            return(gf.CreateMultiPolygon(polyColl));
        }
        else
        {
            return(gf.CreateMultiGeometry(geomColl));
        }
    }