private static FeatureSet NameSearchCity(string name, FeatureType type, SearchRegion region, out long searchTime)
        {
            if (TheRoot.AllStatesByAbbr.TryGetValue(region.Abbr, out State state))
            {
                var projection = ProjectionInfo.FromProj4String(SRID_WGS84);
                projection.Transform = new Transform();
                var featureSet = new FeatureSet(type)
                {
                    Name       = name,
                    Projection = projection,
                };
                var watch = new Stopwatch();
                watch.Start();

                var result = state.AllCitiesByName.Select(item => item.Geom).ToList();

                watch.Stop();
                searchTime = watch.ElapsedMilliseconds;

                PopulateFeatureSet(result, featureSet);
                return(featureSet);
            }

            searchTime = 0;
            return(null);
        }
Exemple #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (ValidateSearchEntries())
            {
                SearchRegion region = null;
                if (rdoPredefinedRegion.Checked)
                {
                    region = cmbPredefinedRegions.SelectedItem as SearchRegion;
                }
                else if (rdoCustomRegion.Checked)
                {
                    var minX = double.Parse(txtRegionMinX.Text);
                    var minY = double.Parse(txtRegionMinY.Text);
                    var maxX = double.Parse(txtRegionMaxX.Text);
                    var maxY = double.Parse(txtRegionMaxY.Text);

                    region = new SearchRegion("Custom", minX, minY, maxX, maxY);
                }

                MultiDimensionalObjectRelationship relationship;
                if (!Enum.TryParse(cmbSearchStrategy.Text, out relationship))
                {
                    relationship = MultiDimensionalObjectRelationship.Intersect;
                }

                SearchAsync(chbLayerNames.CheckedItems.Cast <LayerInfo>().ToArray(), region, relationship);
            }
        }
        private static FeatureSet NameSearchState(string name, FeatureType type, SearchRegion region, out long searchTime)
        {
            var watch = new Stopwatch();

            watch.Start();

            if (TheRoot.AllStatesByAbbr.TryGetValue(region.Abbr, out State result))
            {
                watch.Stop();
                searchTime = watch.ElapsedMilliseconds;
                var projection = ProjectionInfo.FromProj4String(SRID_WGS84);
                projection.Transform = new Transform();
                var featureSet = new FeatureSet(type)
                {
                    Name       = name,
                    Projection = projection,
                };
                PopulateFeatureSet(new[] { result.Geom }, featureSet);
                return(featureSet);
            }

            watch.Stop();
            searchTime = 0;
            return(null);
        }
        private static FeatureSet SpatialSearchOtherSpatialLayers(string layerName, SearchRegion region, MultiDimensionalObjectRelationship relationship, out long searchTime)
        {
            var layer = TheRoot.OtherSpatialLayers[layerName];

            if (layer != null)
            {
                var projection = ProjectionInfo.FromProj4String(SRID_None);
                projection.Transform = new Transform();
                var featureSet = new FeatureSet(FeatureType.Unspecified)
                {
                    Name       = layerName,
                    Projection = projection
                };

                var watch = new Stopwatch();
                watch.Start();

                var result = region == null?layer.Geometries.Cast <JoobGeometry>().ToList()
                                 : layer.Geometries.Search(region.Envelope, relationship).Select(item => item.Key);

                watch.Stop();
                searchTime = watch.ElapsedMilliseconds;

                PopulateFeatureSet(result, featureSet);
                return(featureSet);
            }

            searchTime = 0;
            return(null);
        }
Exemple #5
0
        public void RefreshData()
        {
            SearchRegion.PopulatePredefinedRegions();
            searchRegionBindingSource.DataSource = null;
            searchRegionBindingSource.DataSource = SearchRegion.PredefinedSearchRegions;
            cmbSearchStrategy.SelectedIndex      = 3;

            RefreshLayers();
        }
Exemple #6
0
        private void SearchAsync(IEnumerable <LayerInfo> layerInfos, SearchRegion region, MultiDimensionalObjectRelationship relationship)
        {
            btnSearch.Enabled = false;
            btnSearch.Text    = @"Searching...";

            var searchWorker = new BackgroundWorker();

            searchWorker.DoWork             += SearchWorker_DoWork;
            searchWorker.RunWorkerCompleted += SearchWorker_RunWorkerCompleted;

            _timer.Restart();
            searchWorker.RunWorkerAsync(Tuple.Create(layerInfos, region, relationship, rdoSearchByGeom.Checked));
        }
        public static IEnumerable <FeatureSet> NameSearch(IEnumerable <LayerInfo> layerInfos, SearchRegion region, out long totalSearchTime)
        {
            Debug.Assert(region != null);

            totalSearchTime = 0;
            var result = new List <FeatureSet>();

            foreach (var info in layerInfos)
            {
                long searchTime = 0;
                if (info.Name.Equals(FeatureTypeStates, StringComparison.OrdinalIgnoreCase))
                {
                    var featureSet = NameSearchState(info.Name, FeatureType.Polygon, region, out searchTime);
                    if (featureSet != null)
                    {
                        result.Add(featureSet);
                    }
                }
                else if (info.Name.Equals(FeatureTypeCities, StringComparison.OrdinalIgnoreCase))
                {
                    var featureSet = NameSearchCity(info.Name, FeatureType.Point, region, out searchTime);
                    if (featureSet != null)
                    {
                        result.Add(featureSet);
                    }
                }

                totalSearchTime += searchTime;
            }

            return(result);
        }
        private static FeatureSet SpatialSearch <TMdo, TVal>(JoobRTree <TMdo, TVal> rtree, string name, FeatureType type, SearchRegion region, MultiDimensionalObjectRelationship relationship, out long searchTime)
            where TMdo : JoobObject, IMultiDimensionalObject
            where TVal : JoobObject
        {
            if (rtree.Count > 0)
            {
                var projection = ProjectionInfo.FromProj4String(SRID_WGS84);
                projection.Transform = new Transform();
                var featureSet = new FeatureSet(type)
                {
                    Name       = name,
                    Projection = projection
                };

                var watch = new Stopwatch();
                watch.Start();

                var result = region == null
                    ? rtree.Where(item => item as ObjectWithSpatialInfo != null).Cast <ObjectWithSpatialInfo>().Select(item => item.Geom).ToList()
                    : rtree.Search(region.Envelope as TMdo, relationship).Select(item => item.Key as JoobGeometry).ToList();

                watch.Stop();
                searchTime = watch.ElapsedMilliseconds;

                PopulateFeatureSet(result, featureSet);
                return(featureSet);
            }

            searchTime = 0;
            return(null);
        }
        public static IEnumerable <FeatureSet> SpatialSearch(IEnumerable <LayerInfo> layerInfos, SearchRegion region, MultiDimensionalObjectRelationship relationship, out long totalSearchTime)
        {
            totalSearchTime = 0;
            var result = new List <FeatureSet>();

            foreach (var info in layerInfos)
            {
                long searchTime;
                if (info.Name.Equals(FeatureTypeStates, StringComparison.OrdinalIgnoreCase))
                {
                    var featureSet = SpatialSearch(TheRoot.AllStatesByGeom, info.Name, FeatureType.Polygon, region, relationship, out searchTime);
                    if (featureSet != null)
                    {
                        result.Add(featureSet);
                    }
                }
                else if (info.Name.Equals(FeatureTypeCounties, StringComparison.OrdinalIgnoreCase))
                {
                    var featureSet = SpatialSearch(TheRoot.AllCountiesByGeom, info.Name, FeatureType.Polygon, region, relationship, out searchTime);
                    if (featureSet != null)
                    {
                        result.Add(featureSet);
                    }
                }
                else if (info.Name.Equals(FeatureTypeCities, StringComparison.OrdinalIgnoreCase))
                {
                    var featureSet = SpatialSearch(TheRoot.AllCitiesByGeom, info.Name, FeatureType.Point, region, relationship, out searchTime);
                    if (featureSet != null)
                    {
                        result.Add(featureSet);
                    }
                }
                else
                {
                    var layer = SpatialSearchOtherSpatialLayers(info.Name, region, relationship, out searchTime);
                    if (layer != null)
                    {
                        result.Add(layer);
                    }
                }

                totalSearchTime += searchTime;
            }

            return(result);
        }