Close() public method

Closes the datasource
public Close ( ) : void
return void
Beispiel #1
0
 public void TestTwoOpenClose()
 {
     ///Simulates two threads using the same provider at the same time..
     var provider = new ShapeFile(TestDataPath, false, true);
     provider.Open();
     provider.Open();
     provider.GetGeometriesInView(GetRandomEnvelope());
     provider.Close();
     provider.GetGeometriesInView(GetRandomEnvelope());
     provider.Close();
 }
        /// <summary>
        /// Open a TileIndex shapefile
        /// 
        /// A tileindex is a shapefile that ties together several datasets into a single layer. Therefore, you don’t need to create separate layers for each piece of imagery or each county’s road data; make a tileindex and let SharpMap piece the mosaic together on the fly.
        /// Making a tileindex is easy using gdaltindex for GDAL data sources (rasters). You just run the tool, specifying the index file to create and the list of data sources to add to the index.
        ///
        /// For example, to make a mosaic of several TIFFs:
        ///
        /// gdaltindex imagery.shp imagery/*.tif

        /// See: http://mapserver.org/optimization/tileindex.html
        /// </summary>
        /// <param name="layerName">Name of the layer</param>
        /// <param name="fileName">Path to the ShapeFile containing tile-indexes</param>
        /// <param name="fieldName">FieldName in the shapefile storing full or relative path-names to the datasets</param>
        public GdalTileIndexRasterLayer(string layerName, string fileName, string fieldName) : base(layerName)
        {
            _fileName = fileName;
            _shapeFile = new ShapeFile(fileName, true);
            _shapeFile.Open();
            _extents = _shapeFile.GetExtents();
            _shapeFile.Close();
            _fieldName = fieldName;
        }
Beispiel #3
0
 public void TestTwoThreadsUsingDifferentProviders()
 {
     var provider1 = new ShapeFile(TestDataPath, false, true);
     var provider2 = new ShapeFile(TestDataPath, false, true);
     provider1.Open();
     provider2.Open();
     provider1.GetGeometriesInView(GetRandomEnvelope());
     provider1.Close();
     provider2.GetGeometriesInView(GetRandomEnvelope());
     provider2.Close();
 }
        public JsonResult GetData(float w, float n, float e, float s, int z)
        {
            string format = String.Format("~/App_Data/berlin/{0}", "osmbuildings.shp");
            string path = this.HttpContext.Server.MapPath(format);
            if (!System.IO.File.Exists(path))
                throw new FileNotFoundException("file not found", path);

            Point start = this.GeoToPixel(n, w, z);
            var meta = new { n, w, s, e, x = start.X, y = start.Y, z };

            Envelope bbox = new Envelope();
            bbox.ExpandToInclude(new Coordinate(n, w));
            bbox.ExpandToInclude(new Coordinate(s, e));

            FeatureDataSet ds = new FeatureDataSet();
            using (ShapeFile provider = new ShapeFile(path))
            {
                provider.DoTrueIntersectionQuery = true;
                provider.Open();
                provider.ExecuteIntersectionQuery(bbox, ds);
                provider.Close();
            }

            int zz = MaxZoom - z;
            List<object> data = new List<object>();
            FeatureDataTable table = ds.Tables[0];
            foreach (FeatureDataRow row in table)
            {
                int c = (short)(row["height"]);
                if (c == 0)
                    c = 5; // default value for "null" (zero) heights
                int h = c * ScaleZ >> zz;
                if (h <= 1)
                    h = 1;

                IGeometry geometry = row.Geometry;
                Coordinate[] coords = geometry.Coordinates;
                int total = coords.Length;
                double[] values = new double[total * 2];
                int i = 0;
                foreach (Coordinate curr in coords)
                {
                    Point p = this.GeoToPixel(curr.X, curr.Y, z);
                    values[i++] = p.X - start.X;
                    values[i++] = p.Y - start.Y;
                }
                data.Add(new object[] { h, values });
            }

            return this.Json(new { meta, data }, JsonRequestBehavior.AllowGet);
        }
        public Envelope GetExtents()
        {
            if (BBox == null) {

                using (ShapeFile shapefile = new ShapeFile (ShpFileName)) {
                    shapefile.Open ();

                    // Get extents, assign to svg "viewbox" attribute.
                    BBox = shapefile.GetExtents ();
                    shapefile.Close ();
                }
            }
            return BBox;
        }
        /// <summary>
        /// This method returns a FeatureDataTable containing all the rows from the shapefile that intersect the testGeometry.
        /// The ShapeFile.ExecuteIntersectionQuery method only tests bounding boxes so we use the FilterDelegate property to add a true 
        /// intersection test using NetTopologySuite
        /// </summary>
        /// <param name="pathToShapefile">The path to the shapefile</param>
        /// <param name="testGeometry">The geometry that we want to test against</param>
        /// <returns></returns>
        public FeatureDataTable GetIntersectingFeaturesUsingFilterDelegate(string pathToShapefile, Geometry testGeometry)
        {
            //create a new shapefile provider 
            using (ShapeFile shapefile = new ShapeFile(pathToShapefile))
            {
                //create an nts GeometryFactory
                GeometryFactory geometryFactory = new GeometryFactory();

                //convert the testGeometry into the equivalent NTS geometry
                GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory);

                Geometry check = GeometryConverter.ToSharpMapGeometry(testGeometryAsNtsGeom);
                if (!check.Equals(testGeometry))
                    throw new ApplicationException("conversion error");

                //set the shapefile providers' FilterDelegate property to a new anonymous method
                //this delegate method will be called for each potential row
                shapefile.FilterDelegate = delegate(FeatureDataRow featureDataRow)
                                               {
                                                   //get the geometry from the featureDataRow
                                                   Geometry rowGeometry = featureDataRow.Geometry;
                                                   //convert it to the equivalent NTS geometry
                                                   GeoAPI.Geometries.IGeometry compareGeometryAsNtsGeometry =
                                                           GeometryConverter.ToNTSGeometry(rowGeometry, geometryFactory);
                                                   //do the test. Note that the testGeometryAsNtsGeometry is available here because it is 
                                                   //declared in the same scope as the anonymous method.
                                                   bool intersects =
                                                       testGeometryAsNtsGeom.Intersects(compareGeometryAsNtsGeometry);
                                                   //return the result
                                                   return intersects;
                                               };


                //create a new FeatureDataSet
                FeatureDataSet featureDataSet = new FeatureDataSet();
                //open the shapefile
                shapefile.Open();
                //call ExecuteIntersectionQuery. The FilterDelegate will be used to limit the result set
                shapefile.ExecuteIntersectionQuery(testGeometry, featureDataSet);
                //close the shapefile
                shapefile.Close();
                //return the populated FeatureDataTable
                return featureDataSet.Tables[0];
            }
        }
Beispiel #7
0
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlgOpen = new OpenFileDialog();

            dlgOpen.Filter = "ESRI Shapefiles (*.shp)|*.shp";
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                //lbAssetFields.Items.Clear();
                lbFieldNames.Items.Clear();
                String strFilePath    = dlgOpen.FileName;
                int    iParseFileName = dlgOpen.FileName.LastIndexOf('\\');
                String strFileName    = dlgOpen.FileName.Substring(iParseFileName + 1);
                m_strShapeFilePath   = strFilePath;
                strFilePath          = strFilePath.Substring(0, iParseFileName + 1);
                tbShapeFilePath.Text = m_strShapeFilePath;

                // Set the DBF database connection string
                m_connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";Extended Properties=dBASE IV;User ID=Admin;Password=;";

                // Open the shapefile at the given path
                ShapeFile shapefile = null;
                try
                {
                    shapefile = new SharpMap.Data.Providers.ShapeFile(m_strShapeFilePath);
                    shapefile.Open();
                }
                catch (Exception exc)
                {
                    Global.WriteOutput("Error: Couldn't open shapefile." + exc.Message);
                    return;
                }
                FeatureDataRow fdr = shapefile.GetFeature(0);
                lbFieldNames.Items.Add("GEOMETRY");
                m_htShapefileFields.Clear();
                for (int i = 0; i < fdr.Table.Columns.Count; i++)
                {
                    lbFieldNames.Items.Add(fdr.Table.Columns[i].ColumnName.ToUpper());
                    m_htShapefileFields.Add(fdr.Table.Columns[i].ColumnName.ToUpper(), fdr.Table.Columns[i].DataType.ToString());
                }
                shapefile.Close();
            }
        }
        private Collection<IGeometry> GetBorders()
        {
            Collection<IGeometry> stateBorders;
            using (ShapeFile shapefile = new ShapeFile (ShpFileName)) {
                shapefile.Open ();

                // Get extents, assign to svg "viewbox" attribute.
                Envelope bbox = shapefile.GetExtents ();
                stateBorders = shapefile.GetGeometriesInView (bbox);

                shapefile.Close ();
            }
            return stateBorders;
        }
        /// <summary>
        /// Open a TileIndex shapefile
        /// 
        /// A tileindex is a shapefile that ties together several datasets into a single layer. Therefore, you don’t need to create separate layers for each piece of imagery or each county’s road data; make a tileindex and let SharpMap piece the mosaic together on the fly.
        /// Making a tileindex is easy using gdaltindex for GDAL data sources (rasters). You just run the tool, specifying the index file to create and the list of data sources to add to the index.
        ///
        /// For example, to make a mosaic of several TIFFs:
        ///
        /// gdaltindex imagery.shp imagery/*.tif

        /// See: http://mapserver.org/optimization/tileindex.html
        /// </summary>
        /// <param name="layerName">Name of the layer</param>
        /// <param name="fileName">Path to the ShapeFile containing tile-indexes</param>
        /// <param name="fieldName">FieldName in the shapefile storing full or relative path-names to the datasets</param>
        public GdalTileIndexRasterLayer(string layerName, string fileName, string fieldName) : base(layerName)
        {
            _fileName = fileName;
            _shapeFile = new ShapeFile(fileName, true);
            _shapeFile.Open();
            _extents = _shapeFile.GetExtents();
            _shapeFile.Close();
            _fieldName = fieldName;
            _openDatasets = new Dictionary<string, CacheHolder>();
        }