예제 #1
0
        protected override void OpenCore()
        {
            if (!IsOpenCore)
            {
                isOpen = true;

                if (!File.Exists(idxPathFileName))
                {
                    RtreeSpatialIndex.CreateRectangleSpatialIndex(idxPathFileName, RtreeSpatialIndexPageSize.EightKilobytes, RtreeSpatialIndexDataFormat.Float);

                    rTreeIndex = new RtreeSpatialIndex(idxPathFileName, RtreeSpatialIndexReadWriteMode.ReadWrite);
                    rTreeIndex.Open();

                    foreach (var rasterLayer in rasterLayers)
                    {
                        rasterLayer.Open();
                        RectangleShape boudingBox = rasterLayer.GetBoundingBox();

                        Feature feature = new Feature(boudingBox);
                        feature.Id = rasterLayer.PathFilename;
                        rTreeIndex.Add(feature);
                    }
                }
                else
                {
                    rTreeIndex = new RtreeSpatialIndex(idxPathFileName, RtreeSpatialIndexReadWriteMode.ReadOnly);
                    rTreeIndex.Open();
                }
            }
        }
        private static void BuildIndex(BasFeatureEntity featureEntity, RtreeSpatialIndex openedRtree, Projection openedProjection)
        {
            if (featureEntity != null)
            {
                BaseShape newShape = featureEntity.Shape;
                if (openedProjection != null)
                {
                    newShape    = openedProjection.ConvertToExternalProjection(featureEntity.Shape);
                    newShape.Id = featureEntity.Id;
                }

                openedRtree.Add(newShape);
            }
        }
        protected virtual void BuildIndexFileCore(bool rebuild)
        {
            string idxPathFileName = Path.ChangeExtension(CsvPathFileName, ".idx");
            string idsPathFileName = Path.ChangeExtension(CsvPathFileName, ".ids");

            if (!File.Exists(idxPathFileName) && !File.Exists(idsPathFileName) || rebuild)
            {
                if (!string.IsNullOrEmpty(WktColumnName))
                {
                    RtreeSpatialIndex.CreateRectangleSpatialIndex(idxPathFileName, RtreeSpatialIndexPageSize.EightKilobytes, RtreeSpatialIndexDataFormat.Float);
                }
                else
                {
                    RtreeSpatialIndex.CreatePointSpatialIndex(idxPathFileName, RtreeSpatialIndexPageSize.EightKilobytes, RtreeSpatialIndexDataFormat.Float);
                }

                using (RtreeSpatialIndex tempRTree = new RtreeSpatialIndex(idxPathFileName, GeoFileReadWriteMode.ReadWrite))
                {
                    tempRTree.Open();
                    bool     isCanceled = false;
                    DateTime startDate  = DateTime.Now;
                    using (var csvReader = CreateCsvReader())
                    {
                        var allRecords = csvReader.DataRecords.ToArray();
                        int index      = 0;
                        foreach (var currentDataRecord in allRecords)
                        {
                            index++;
                            var feature = GetFeature(index.ToString(), currentDataRecord);
                            if (feature != null)
                            {
                                tempRTree.Add(feature);
                                BuildingIndexCsvFeatureSourceEventArgs e = new BuildingIndexCsvFeatureSourceEventArgs(allRecords.Length, index, feature, startDate, false);
                                OnBuildingIndex(e);
                                if (e.Cancel)
                                {
                                    isCanceled = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!isCanceled)
                    {
                        tempRTree.Flush();
                    }
                    else
                    {
                        if (File.Exists(idxPathFileName))
                        {
                            File.Delete(idxPathFileName);
                        }
                        if (File.Exists(idsPathFileName))
                        {
                            File.Delete(idsPathFileName);
                        }
                    }
                }
            }
        }