Пример #1
0
        public LayerData GetData()
        {
            var spatialReference = _ogrLayer.GetSpatialRef();

            spatialReference.ExportToPrettyWkt(out string spref, 0);
            var layer = new LayerData
            {
                Name             = _ogrLayer.GetName(),
                GoemType         = _ogrLayer.GetGeomType().ToString("G").Substring(3),
                FeatureCount     = _ogrLayer.GetFeatureCount(0),
                Extent           = GetExtent(_ogrLayer),
                SpatialRefSystem = spref,
                ProjectionName   = spatialReference.GetName()
            };

            return(layer);
        }
Пример #2
0
        //从文件中读取数据
        private static FeatureSource GetFeaturesource(SHPGeoDataBase thisdb, String path)
        {
            OSGeo.OGR.DataSource ds = GetOGRDataSource(thisdb, path);

            //init schema
            OSGeo.OGR.Layer       layer = ds.GetLayerByIndex(0);
            OSGeo.OGR.FeatureDefn fd    = layer.GetLayerDefn();
            Int32  sIndex     = path.LastIndexOf("\\");
            string sname      = path.Substring(sIndex + 1, path.Length - sIndex - 1 - 4);
            int    fieldcount = fd.GetFieldCount();
            Dictionary <String, FieldDefn> tmpField = new Dictionary <string, FieldDefn>();

            for (int i = 0; i < fieldcount; ++i)
            {
                OSGeo.OGR.FieldDefn field = fd.GetFieldDefn(i);
                tmpField.Add(field.GetName(), field);
            }
            GisSmartTools.RS.ReferenceSystem rfs;
            OSGeo.OSR.SpatialReference       osrrf = layer.GetSpatialRef();
            if (osrrf.IsProjected() != 0)
            {
                rfs = new GisSmartTools.RS.SRS(osrrf);
            }
            else
            {
                rfs = new GisSmartTools.RS.GRS(osrrf);
            }
            Schema rs = new Schema(sname, layer.GetGeomType(), rfs, tmpField);
            //get featurecollection
            FeatureCollection fc = GetFeatureCollection(layer, rs);

            //close file
            //ds.Dispose();

            return(new FeatureSource(rs, fc));
        }
Пример #3
0
        public static void selectDZXFromPoint(string point, string dzx, string savePath)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver     dr    = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
            OSGeo.OGR.DataSource poiDS = dr.Open(point, 0);
            OSGeo.OGR.DataSource dzxDS = dr.Open(dzx, 0);
            if (File.Exists(savePath))
            {
                File.Delete(savePath);
            }
            OSGeo.OGR.DataSource newDS    = dr.CreateDataSource(savePath, null);
            OSGeo.OGR.Layer      poiLayer = poiDS.GetLayerByIndex(0);
            OSGeo.OGR.Layer      dzxLayer = dzxDS.GetLayerByIndex(0);
            OSGeo.OGR.Layer      newLayer = newDS.CreateLayer("", dzxLayer.GetSpatialRef(), dzxLayer.GetGeomType(), null);

            int poiCount = poiLayer.GetFeatureCount(0);
            int dzxCount = dzxLayer.GetFeatureCount(0);

            for (int i = 0; i < poiCount; i++)
            {
                OSGeo.OGR.Feature  poiFeat = poiLayer.GetFeature(i);
                OSGeo.OGR.Geometry poiGeom = poiFeat.GetGeometryRef();
                for (int t = 0; t < dzxCount; t++)
                {
                    OSGeo.OGR.Feature  dzxFeat = dzxLayer.GetFeature(t);
                    OSGeo.OGR.Geometry dzxGeom = dzxFeat.GetGeometryRef();

                    if (poiGeom.Within(dzxGeom))
                    {
                        newLayer.CreateFeature(dzxFeat);
                    }
                    dzxFeat.Dispose();
                    Console.WriteLine("getFeatureByPoint:{0}/{1}", i, poiCount);
                }
                poiFeat.Dispose();
            }
            Console.WriteLine("【本次提取到{0}个要素】", newLayer.GetFeatureCount(0));
            newDS.Dispose();
            dzxDS.Dispose();
            poiDS.Dispose();
        }