コード例 #1
0
ファイル: Program.cs プロジェクト: jugstalt/gview5
        static private string GetBBox(IEnvelope env, IGeometricTransformer transformer)
        {
            try
            {
                env = ((IGeometry)transformer.Transform2D(env)).Envelope;

                return(Math.Round(env.minx, 7).ToString(_nhi) + "," +
                       Math.Round(env.miny, 7).ToString(_nhi) + "," +
                       Math.Round(env.maxx, 7).ToString(_nhi) + "," +
                       Math.Round(env.maxy, 7).ToString(_nhi));
            }
            catch { return(String.Empty); }
        }
コード例 #2
0
        public static void Feature2GML(IFeature feature, IFeatureClass fc, string fcID, StringBuilder sb, string srsName, IGeometricTransformer transformer, GmlVersion version)
        {
            if (feature == null || fc == null)
            {
                return;
            }

            sb.Append(@"
   <gml:featureMember>
      <gv:" + fcID + " gml:id=\"" + fcID + "." + feature.OID + "\">");

            // Shape
            IGeometry shape = (transformer != null) ? transformer.Transform2D(feature.Shape) as IGeometry : feature.Shape;

            if (shape != null)
            {
                sb.Append(@"
         <gml:boundedBy>");
                sb.Append(GeometryTranslator.Geometry2GML(shape.Envelope, srsName, version));
                sb.Append(@"
         </gml:boundedBy>");

                sb.Append(@"
         <gv:" + fc.ShapeFieldName.Replace("#", "") + ">");
                sb.Append(GeometryTranslator.Geometry2GML(shape, srsName, version));
                sb.Append(@"
         </gv:" + fc.ShapeFieldName.Replace("#", "") + ">");
            }

            // Fields
            foreach (FieldValue fv in feature.Fields)
            {
                if (fv.Name == fc.ShapeFieldName)
                {
                    continue;
                }

                // TODO: Value soll noch auf <,>,&,... untersucht werden !!!
                sb.Append(@"
         <gv:" + fv.Name.Replace("#", "") + ">" + fv.Value + "</gv:" + fv.Name.Replace("#", "") + ">");
            }
            sb.Append(@"
      </gv:" + fcID + @">
   </gml:featureMember>");
        }
コード例 #3
0
        public void Draw(ISymbol symbol, IGeometry geometry)
        {
            try
            {
                IGeometry geom;
                if (_geoTransformer != null)
                {
                    geom = (IGeometry)_geoTransformer.Transform2D(geometry);
                }
                else
                {
                    geom = geometry;
                }

                symbol.Draw(this, geom);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
        }
コード例 #4
0
        static public IGeometry Transform2D(IGeometry geometry, ISpatialReference from, ISpatialReference to)
        {
            if (geometry == null)
            {
                return(null);
            }

            if (from == null || to == null || from.Equals(to))
            {
                return(geometry);
            }

            using (IGeometricTransformer transformer = GeometricTransformerFactory.Create())
            {
                //transformer.FromSpatialReference = from;
                //transformer.ToSpatialReference = to;
                transformer.SetSpatialReferences(from, to);
                IGeometry transformed = transformer.Transform2D(geometry) as IGeometry;
                transformer.Release();

                return(transformed);
            }
        }
コード例 #5
0
        public IGeometry Transform(IGeometry geometry, ISpatialReference geometrySpatialReference)
        {
            if (geometry == null)
            {
                return(null);
            }

            if (geometrySpatialReference == null || _spatialReference == null || geometrySpatialReference.Equals(_spatialReference))
            {
                return(geometry);
            }

            IGeometricTransformer transformer = GeometricTransformerFactory.Create();

            //transformer.FromSpatialReference = geometrySpatialReference;
            //transformer.ToSpatialReference = _spatialReference;
            transformer.SetSpatialReferences(geometrySpatialReference, _spatialReference);

            IGeometry geom = transformer.Transform2D(geometry) as IGeometry;

            transformer.Release();

            return(geom);
        }
コード例 #6
0
        async private Task <DualTree> SpatialIndex(IFeatureClass fc, int maxPerNode, List <IQueryFilter> filters)
        {
            if (fc == null || fc.Envelope == null)
            {
                return(null);
            }

            if (filters == null)
            {
                QueryFilter filter = new QueryFilter();
                filter.AddField(fc.ShapeFieldName);
                filters = new List <IQueryFilter>();
                filters.Add(filter);
            }

            DualTree dualTree = new DualTree(maxPerNode);

            foreach (IQueryFilter filter in filters)
            {
                IFeatureCursor fCursor = await fc.GetFeatures(filter);

                if (fCursor == null)
                {
                    _errMsg = "Fatal error: sourcedb query failed...";
                    return(null);
                }

                if (ReportAction != null)
                {
                    ReportAction(this, "Calculate spatial index");
                }
                IEnvelope fcEnvelope = fc.Envelope;
                if (_transformer != null)
                {
                    IGeometry geom = _transformer.Transform2D(fcEnvelope) as IGeometry;
                    if (geom == null)
                    {
                        _errMsg = "SpatialIndex: Can't project featureclass extent!";
                        return(null);
                    }
                    fcEnvelope = geom.Envelope;
                }
                dualTree.CreateTree(fcEnvelope);  // hier projezieren

                int      counter = 0;
                IFeature feat;
                while ((feat = await fCursor.NextFeature()) != null)
                {
                    if (!_cancelTracker.Continue)
                    {
                        break;
                    }

                    SHPObject shpObj;

                    IGeometry shape = feat.Shape;
                    if (_transformer != null)
                    {
                        shape = _transformer.Transform2D(shape) as IGeometry;
                    }

                    if (shape != null)
                    {
                        shpObj = new SHPObject((int)((uint)feat.OID), shape.Envelope);
                    }
                    else
                    {
                        shpObj = new SHPObject((int)((uint)feat.OID), null);
                    }

                    dualTree.AddShape(shpObj);
                    if ((counter % 1000) == 0 && ReportProgress != null)
                    {
                        ReportProgress(this, counter);
                    }
                    counter++;
                }
                dualTree.FinishIt();
                fCursor.Dispose();

                if (ReportProgress != null)
                {
                    ReportProgress(this, counter);
                }
            }
            return(dualTree);
        }
コード例 #7
0
        private bool CopyFeatures(IFeatureClass source, IFeatureUpdater fdb, IFeatureClass dest, FieldTranslation fTrans, List <IQueryFilter> filters)
        {
            if (filters == null)
            {
                QueryFilter filter = new QueryFilter();
                filter.SubFields = "*";

                filters = new List <IQueryFilter>();
                filters.Add(filter);
            }

            int             counter  = 0;
            List <IFeature> features = new List <IFeature>();

            foreach (IQueryFilter filter in filters)
            {
                using (IFeatureCursor cursor = source.GetFeatures(filter))
                {
                    IFeature feature;
                    while ((feature = cursor.NextFeature) != null)
                    {
                        if (fTrans != null)
                        {
                            fTrans.RenameFields(feature);
                        }
                        if (_transformer != null)
                        {
                            feature.Shape = _transformer.Transform2D(feature.Shape) as IGeometry;
                        }
                        features.Add(feature);
                        counter++;
                        if ((counter % this.FeatureBufferSize) == 0)
                        {
                            if (!fdb.Insert(dest, features))
                            {
                                _errMsg = "Fatal error: destdb insert failed...\n" + fdb.lastErrorMsg;
                                return(false);
                            }
                            features.Clear();
                            if (ReportProgress != null)
                            {
                                ReportProgress(this, counter);
                            }
                        }
                    }
                }
            }
            if (features.Count > 0)
            {
                if (!fdb.Insert(dest, features))
                {
                    _errMsg = "Fatal error: destdb insert failed...";
                    return(false);
                }
                features.Clear();
                if (ReportProgress != null)
                {
                    ReportProgress(this, counter);
                }
            }
            return(true);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: jugstalt/gview5
        static private Dictionary <string, object> ParseFeature(string metaId, string category, IFeature feature, Item proto, bool useGeometry, IGeometricTransformer transformer, ImportConfig.FeatureClassDefinition featureClassDef)
        {
            var replace = featureClassDef.Replacements;

            var result = new Dictionary <string, object>();

            string oid = feature.OID.ToString();

            if (feature.OID <= 0 && !String.IsNullOrWhiteSpace(featureClassDef.ObjectOidField))
            {
                var idFieldValue = feature.FindField(featureClassDef.ObjectOidField);
                if (idFieldValue != null)
                {
                    oid = idFieldValue.Value?.ToString();
                }
            }

            result["id"]             = metaId + "." + oid;
            result["suggested_text"] = ParseFeatureField(feature, proto.SuggestedText);
            result["subtext"]        = ParseFeatureField(feature, proto.SubText);
            result["thumbnail_url"]  = ParseFeatureField(feature, proto.ThumbnailUrl);
            result["category"]       = category;

            if (replace != null)
            {
                foreach (var r in replace)
                {
                    result["suggested_text"] = result["suggested_text"]?.ToString().Replace(r.From, r.To);
                    result["subtext"]        = result["subtext"]?.ToString().Replace(r.From, r.To);
                }
            }

            if (useGeometry == true && feature.Shape != null)
            {
                IGeometry shape = feature.Shape;

                if (shape is IPoint)
                {
                    IPoint point = (IPoint)transformer.Transform2D(feature.Shape);
                    //result["longitude"] = point.X;
                    //result["latitude"] = point.Y;
                    result["geo"] = new LuceneServerNET.Core.Models.Spatial.GeoPoint()
                    {
                        Longidute = point.X,
                        Latitude  = point.Y
                    };
                }
                else if (shape is IPolyline)
                {
                    IEnvelope env = shape.Envelope;
                    if (env != null)
                    {
                        IPoint point = Algorithm.PolylinePoint((IPolyline)shape, ((IPolyline)shape).Length / 2.0);

                        if (point != null)
                        {
                            point = (IPoint)transformer.Transform2D(point);
                            //result["longitude"] = point.X;
                            //result["latitude"] = point.Y;
                            result["geo"] = new LuceneServerNET.Core.Models.Spatial.GeoPoint()
                            {
                                Longidute = point.X,
                                Latitude  = point.Y
                            };
                        }

                        result["bbox"] = GetBBox(env, transformer);
                    }
                }
                else if (shape is IPolygon)
                {
                    IEnvelope env = shape.Envelope;
                    if (env != null)
                    {
                        var points = Algorithm.OrderPoints(Algorithm.PolygonLabelPoints((IPolygon)shape), env.Center);
                        if (points != null && points.PointCount > 0)
                        {
                            IPoint point = (IPoint)transformer.Transform2D(points[0]);
                            //result["longitude"] = point.X;
                            //result["latitude"] = point.Y;
                            result["geo"] = new LuceneServerNET.Core.Models.Spatial.GeoPoint()
                            {
                                Longidute = point.X,
                                Latitude  = point.Y
                            };
                        }

                        result["bbox"] = GetBBox(env, transformer);
                    }
                }
            }

            return(result);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: jugstalt/gview5
        static private Item ParseFeature(string metaId, string category, IFeature feature, Item proto, bool useGeometry, IGeometricTransformer transformer, ImportConfig.FeatureClassDefinition featureClassDef)
        {
            var replace = featureClassDef.Replacements;

            var result = new Item();

            string oid = feature.OID.ToString();

            if (feature.OID <= 0 && !String.IsNullOrWhiteSpace(featureClassDef.ObjectOidField))
            {
                var idFieldValue = feature.FindField(featureClassDef.ObjectOidField);
                if (idFieldValue != null)
                {
                    oid = idFieldValue.Value?.ToString();
                }
            }

            result.Id            = metaId + "." + oid;
            result.SuggestedText = ParseFeatureField(feature, proto.SuggestedText);
            result.SubText       = ParseFeatureField(feature, proto.SubText);
            result.ThumbnailUrl  = ParseFeatureField(feature, proto.ThumbnailUrl);
            result.Category      = category;

            if (replace != null)
            {
                foreach (var r in replace)
                {
                    result.SuggestedText = result.SuggestedText?.Replace(r.From, r.To);
                    result.SubText       = result.SubText?.Replace(r.From, r.To);
                }
            }

            if (useGeometry == true && feature.Shape != null)
            {
                IGeometry shape = feature.Shape;

                if (shape is IPoint)
                {
                    IPoint point = (IPoint)transformer.Transform2D(feature.Shape);
                    result.Geo = new Nest.GeoLocation(point.Y, point.X);
                }
                else if (shape is IPolyline)
                {
                    IEnvelope env = shape.Envelope;
                    if (env != null)
                    {
                        IPoint point = Algorithm.PolylinePoint((IPolyline)shape, ((IPolyline)shape).Length / 2.0);

                        if (point != null)
                        {
                            point      = (IPoint)transformer.Transform2D(point);
                            result.Geo = new Nest.GeoLocation(point.Y, point.X);
                        }

                        result.BBox = GetBBox(env, transformer);
                    }
                }
                else if (shape is IPolygon)
                {
                    IEnvelope env = shape.Envelope;
                    if (env != null)
                    {
                        var points = Algorithm.OrderPoints(Algorithm.PolygonLabelPoints((IPolygon)shape), env.Center);
                        if (points != null && points.PointCount > 0)
                        {
                            IPoint point = (IPoint)transformer.Transform2D(points[0]);
                            result.Geo = new Nest.GeoLocation(point.Y, point.X);
                        }

                        result.BBox = GetBBox(env, transformer);
                    }
                }
            }

            return(result);
        }