public TobinBasFeatureLayer(string tobinBasFileName)
 {
     minAnnotationFontSize          = 5;
     progressiveDrawingRecordsCount = 12000;
     this.tobinBasFilePathName      = tobinBasFileName;
     FeatureSource = new TobinBasFeatureSource(tobinBasFileName);
 }
        public static void BuildIndexFile(string pathFilename)
        {
            //Validators.CheckParameterIsNotNull(pathFilename, "pathFileName");
            //Validators.CheckShapeFileNameIsValid(pathFilename, "pathFileName");

            TobinBasFeatureSource.BuildIndexFile(pathFilename);
        }
Esempio n. 3
0
        protected override void BuildIndexCore(FeatureLayer featureLayer)
        {
            TobinBasFeatureSource.BuildingIndex += TobinBasFeatureSource_BuildingIndex;
            var uri = LayerPlugin.GetUri(featureLayer);

            if (uri != null)
            {
                TobinBasFeatureSource.BuildIndexFile(uri.LocalPath, Path.ChangeExtension(uri.LocalPath, ".idx"), null, string.Empty, string.Empty, BuildIndexMode.DoNotRebuild);
            }
        }
        public static void BuildIndexFile(string basPathFilename, string indexPathFilename, Projection projection, string columnName, string regularExpression, BuildIndexMode buildIndexMode, Encoding encoding)
        {
            //Validators.CheckParameterIsNotNullOrEmpty(basPathFilename, "shapePathFileName");
            //Validators.CheckShapeFileNameIsValid(basPathFilename, "shapePathFileName");
            //Validators.CheckParameterIsNotNullOrEmpty(indexPathFilename, "indexPathFileName");
            //Validators.CheckParameterIsNotNull(columnName, "columnName");
            //Validators.CheckParameterIsNotNull(regularExpression, "regularExpression");
            //Validators.CheckParameterIsNotNull(encoding, "encoding");
            //Validators.CheckBuildIndexModeIsValid(buildIndexMode, "buildIndexMode");

            string tmpIndexPathFilename = Path.GetDirectoryName(indexPathFilename) + "\\TMP" + Path.GetFileName(indexPathFilename);

            if (!(File.Exists(indexPathFilename) && File.Exists(Path.ChangeExtension(indexPathFilename, ".ids"))) || buildIndexMode == BuildIndexMode.Rebuild)
            {
                RtreeSpatialIndex rTreeIndex = new RtreeSpatialIndex(tmpIndexPathFilename, GeoFileReadWriteMode.ReadWrite);

                TobinBasFeatureSource featureSource = new TobinBasFeatureSource(basPathFilename);
                featureSource.Encoding     = encoding;
                featureSource.RequireIndex = false;
                featureSource.Open();
                if (projection != null)
                {
                    if (!projection.IsOpen)
                    {
                        projection.Open();
                    }
                }
                try
                {
                    //// TODO Make sure the rtree will open only once.
                    //ShapeFileType shapeType = ShapeFileType.Null;

                    //ShapeFileType currentRecordType = featureSource.basReader.GetShapeFileType();
                    //shapeType = currentRecordType;
                    RtreeSpatialIndex.CreateRectangleSpatialIndex(tmpIndexPathFilename, RtreeSpatialIndexPageSize.EightKilobytes, RtreeSpatialIndexDataFormat.Float);
                    rTreeIndex.Open();

                    Collection <BasFeatureEntity> allFeatureEntities = featureSource.basReader.GetAllFeatureEntities();

                    int recordCount = allFeatureEntities.Count;

                    DateTime startProcessTime = DateTime.Now;

                    for (int i = 0; i < recordCount; i++)
                    {
                        BasFeatureEntity currentShape = null;
                        currentShape = allFeatureEntities[i];

                        long   offset = currentShape.Offset;
                        string id     = offset.ToString(CultureInfo.InvariantCulture);;

                        if (currentShape != null)
                        {
                            bool isMatch = false;
                            if (string.IsNullOrEmpty(columnName) && string.IsNullOrEmpty(regularExpression))
                            {
                                isMatch = true;
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(columnName))
                                {
                                    string columnValue = featureSource.GetValueByColumnName(id.ToString(CultureInfo.InvariantCulture), columnName);
                                    isMatch = Regex.IsMatch(columnValue, regularExpression, RegexOptions.IgnoreCase);
                                }
                            }

                            if (isMatch)
                            {
                                currentShape.Id = id;

                                BuildingIndexBasFileFeatureSourceEventArgs buildingIndexBasFileFeatureSourceEventArgs = new BuildingIndexBasFileFeatureSourceEventArgs(recordCount, offset, new Feature(currentShape.Shape), startProcessTime, false, basPathFilename, i);
                                OnBuildingIndex(buildingIndexBasFileFeatureSourceEventArgs);
                                if (!buildingIndexBasFileFeatureSourceEventArgs.Cancel)
                                {
                                    BuildIndex(currentShape, rTreeIndex, projection);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    rTreeIndex.Flush();
                    rTreeIndex.Close();
                }
                finally
                {
                    if (rTreeIndex != null)
                    {
                        rTreeIndex.Close();
                    }
                    if (featureSource != null)
                    {
                        featureSource.Close();
                    }
                    if (projection != null)
                    {
                        projection.Close();
                    }

                    // Replace the old file.
                    MoveFile(tmpIndexPathFilename, indexPathFilename);
                    MoveFile(Path.ChangeExtension(tmpIndexPathFilename, ".ids"), Path.ChangeExtension(indexPathFilename, ".ids"));

                    DeleteFile(tmpIndexPathFilename);
                    DeleteFile(Path.ChangeExtension(tmpIndexPathFilename, ".ids"));
                }
            }
        }