Beispiel #1
0
        private NetTopologySuite.Features.Feature getFeature(ReferenceGeometry g, GeomType type)
        {
            List <Coordinate> coordinatesSwissGrid = new List <Coordinate>();

            Coordinate[] coordinates;
            if (type == GeomType.Point)
            {
                coordinates = g.Point.Coordinates;
            }
            else if (type == GeomType.Line)
            {
                coordinates = g.Line.Coordinates;
            }
            else if (type == GeomType.Polygon)
            {
                coordinates = g.Polygon.Coordinates;
            }
            else
            {
                coordinates = null;
            }
            foreach (Coordinate coor in coordinates)
            {
                // Convert Coordinates to LV03
                double x = 0, y = 0, h = 0;
                CoordinateConverter.WGS84toLV03(coor.Y, coor.X, 0, ref x, ref y, ref h);

                Coordinate newcoord = new Coordinate(x, y);
                coordinatesSwissGrid.Add(newcoord);
            }
            try
            {
                var      gf = new GeometryFactory();
                Geometry polygonSwissGrid = null;
                if (type == GeomType.Point)
                {
                    polygonSwissGrid = gf.CreatePoint(coordinatesSwissGrid[0]);
                }
                else if (type == GeomType.Line)
                {
                    polygonSwissGrid = gf.CreateLineString(coordinatesSwissGrid.ToArray());
                }
                else if (type == GeomType.Polygon)
                {
                    polygonSwissGrid = gf.CreatePolygon(coordinatesSwissGrid.ToArray());
                }

                NetTopologySuite.Features.AttributesTable attribute = new NetTopologySuite.Features.AttributesTable();
                attribute.Add("id", g.GeometryId);
                attribute.Add("name", g.GeometryName);


                NetTopologySuite.Features.Feature i = new NetTopologySuite.Features.Feature(polygonSwissGrid, attribute);
                return(i);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        /// <summary>
        /// Creates a GeoJson from all ProjectGeometries in the current project (session has to be set)
        /// </summary>
        /// <returns>GeoJson string</returns>
        private string createGeoJson()
        {
            string projectId = HttpContext.Session.GetString("Project");

            if (projectId == null)
            {
                return("");
            }

            //TODO chb
            //Project myProject = db.Projects.Include(m => m.Geometries).Where(m => m.ProjectId == new Guid(projectId)).FirstOrDefault();
            Project myProject = db.Projects
                                .Include(p => p.ProjectGroups).ThenInclude(m => m.Geometries)
                                .Where(m => m.ProjectId == new Guid(projectId)).FirstOrDefault();

            if (myProject == null)
            {
                return("");
            }

            if (myProject != null)
            {
                NetTopologySuite.Features.FeatureCollection featureCollection = new NetTopologySuite.Features.FeatureCollection();

                //TODO chb
                //foreach (ReferenceGeometry g in myProject.Geometries.Where(m => m.StatusId != StatusEnum.deleted))
                foreach (ReferenceGeometry g in myProject.ProjectGroups.SelectMany(pg => pg.Geometries).Where(g => g.StatusId != StatusEnum.deleted))
                {
                    NetTopologySuite.Features.Feature f = null;
                    if (g.Point != null)
                    {
                        f = getFeature(g, GeomType.Point);
                    }
                    if (g.Line != null)
                    {
                        f = getFeature(g, GeomType.Line);
                    }
                    if (g.Polygon != null)
                    {
                        f = getFeature(g, GeomType.Polygon);
                    }
                    if (f != null)
                    {
                        featureCollection.Add(f);
                    }
                }


                var jsonSerializer = GeoJsonSerializer.Create();
                var sw             = new System.IO.StringWriter();
                jsonSerializer.Serialize(sw, featureCollection);

                return(sw.ToString());
            }
            else
            {
                return(null);// "No project found";
            }
        }
Beispiel #3
0
        public static RadioInfo FromFeature(NetTopologySuite.Features.Feature f)
        {
            var    ret  = new RadioInfo();
            string prov = f.Attributes["PROV"] as string;
            string dpto = f.Attributes["DEPTO"] as string;
            string frac = f.Attributes["FRAC"] as string;
            string rad  = f.Attributes["RADIO"] as string;

            ret.Prov     = prov;
            ret.Dpto     = dpto;
            ret.Fraccion = frac;
            ret.Radio    = rad;
            return(ret);
        }
Beispiel #4
0
        public static RadioInfo FromFeatureRedcode(NetTopologySuite.Features.Feature f, string redcodeField = "REDCODE")
        {
            var    ret  = new RadioInfo();
            string data = f.Attributes[redcodeField] as string;
            string prov = data.Substring(0, 2);
            string dpto = data.Substring(2, 3);
            string frac = data.Substring(5, 2);
            string rad  = data.Substring(7, 2);

            ret.Prov     = prov;
            ret.Dpto     = dpto;
            ret.Fraccion = frac;
            ret.Radio    = rad;
            return(ret);
        }
Beispiel #5
0
        GameObject GenerateModel(QuadTreeNode node, NetTopologySuite.Features.Feature feature)
        {
            var featureData = DataByNode[node];

            var    cnam     = feature.Attributes["CNAM"].ToString();
            string facc     = feature.Attributes["FACC"].ToString();
            int    fsc      = int.Parse(feature.Attributes["FSC"].ToString());
            string modl     = feature.Attributes["MODL"].ToString();
            var    rotation = feature.Attributes["AO1"].ToString();

            var    cdbTile     = featureData.CDBTileByFeature[feature];
            string fullZipPath = Database.DB.GSModelGeometry.GeometryArchive.Filename(cdbTile);
            string zipPath     = Path.GetDirectoryName(fullZipPath);
            string zipFilename = Path.GetFileName(fullZipPath);
            string fltFilename = Database.DB.GSModelGeometry.GeometryArchive.Filename(cdbTile, facc, fsc, modl) + ".flt";

            float heading = 0f;

            if (float.TryParse(rotation, out heading))
            {
                if (heading < 0f || heading >= 360f)
                {
                    Debug.LogWarningFormat("feature rotation: {0} is outside of established range [0-360)", heading);
                }
            }
            else
            {
                Debug.LogError("could not find/parse rotation of feature - using default rotation");
            }

            var gameObj = new GameObject(modl);
            var model   = gameObj.AddComponent <Model>();

            model.Path            = Path.GetDirectoryName(fullZipPath);
            model.ZipFilename     = zipFilename;
            model.FltFilename     = Path.GetFileName(fltFilename);
            model.ModelManager    = Database.ModelManager;
            model.MaterialManager = Database.MaterialManager;
            model.MeshManager     = Database.MeshManager;
            model.Feature         = feature;
            gameObj.transform.SetParent(node.Root.transform, false);
            gameObj.transform.localScale = (float)Database.Projection.Scale * Vector3.one;
            gameObj.transform.position   = featureData.PositionByFeature[feature];
            gameObj.transform.rotation   = Quaternion.Euler(0f, heading, 0f);
            model.ModelManager.Add(model);
            model.StartCoroutine("Load");
            return(gameObj);
        }
Beispiel #6
0
        public int CompareByDistance2(NetTopologySuite.Features.Feature a, NetTopologySuite.Features.Feature b)
        {
            if (a == b)
            {
                return(0);
            }

            if (a == null)
            {
                return(1);
            }
            if (b == null)
            {
                return(-1);
            }

            Vector3 avec = Vector3.zero, bvec = Vector3.zero;
            bool    afound = PositionByFeature.TryGetValue(a, out avec);
            bool    bfound = PositionByFeature.TryGetValue(b, out bvec);

            if (!afound && !bfound)
            {
                return(0);
            }

            if (!afound)
            {
                return(1);
            }
            if (!bfound)
            {
                return(-1);
            }

            float adist = (avec - CameraPosition).sqrMagnitude;
            float bdist = (bvec - CameraPosition).sqrMagnitude;

            return(adist.CompareTo(bdist));
        }
Beispiel #7
0
        public int CompareByDistance2_Reverse(NetTopologySuite.Features.Feature a, NetTopologySuite.Features.Feature b)
        {
            int result = CompareByDistance2(a, b);

            return(-1 * result);
        }
        private void filterGeoPosition(String fileName, double minX, double maxX, double minY, double maxY)
        {
            var jsonDoc     = "";
            var batch       = new List <string>();
            var boundingBox = new NetTopologySuite.Geometries.Envelope(minX, maxX, minY, maxY);
            var feature     = new NetTopologySuite.Features.Feature();

            using (FileStream s = File.Open(fileName, FileMode.Open))
                using (var streamReader = new StreamReader(s))
                {
                    var file      = Path.GetFileNameWithoutExtension(fileName).Split(".");
                    var topicname = file[1];

                    using (var jsonreader = new Newtonsoft.Json.JsonTextReader(streamReader))
                    {
                        while (jsonreader.Read())
                        {
                            var reader = new NetTopologySuite.IO.GeoJsonReader();
                            if (jsonreader.TokenType == Newtonsoft.Json.JsonToken.StartObject)
                            {
                                while (jsonreader.Read())
                                {
                                    if (jsonreader.TokenType == Newtonsoft.Json.JsonToken.StartArray)
                                    {
                                        while (jsonreader.Read())
                                        {
                                            try
                                            {
                                                if (jsonreader != null)
                                                {
                                                    feature = reader.Read <NetTopologySuite.Features.Feature>(jsonreader);
                                                }

                                                var geo = feature.Geometry;
                                                var atr = feature.Attributes;
                                                if (boundingBox.Intersects(geo.EnvelopeInternal))
                                                {
                                                    jsonDoc = createGeoObject(atr, geo);
                                                    batch.Add(jsonDoc);
                                                    if (batch.Count >= 5000)
                                                    {
                                                        _producer.Produce(topicname, batch);
                                                        _logger.LogInformation("Wrote " + batch.Count + " objects into " + topicname);
                                                        batch.Clear();
                                                    }
                                                }
                                            }
                                            //Loop gives reader exception when it reaches the last element from the file
                                            catch (Newtonsoft.Json.JsonReaderException e)
                                            {
                                                _logger.LogError("Error writing data: {0}.", e.GetType().Name);
                                                var geo = feature.Geometry;
                                                var atr = feature.Attributes;

                                                jsonDoc = createGeoObject(atr, geo);
                                                batch.Add(jsonDoc);
                                                _producer.Produce(topicname, batch);
                                                _logger.LogInformation("Wrote " + batch.Count + " objects into " + topicname);
                                                batch.Clear();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            if (batch != null)
                            {
                                _producer.Produce(topicname, batch);
                                _logger.LogInformation("Wrote " + batch.Count + " objects into " + topicname);
                                batch.Clear();
                            }
                        }
                    }
                }
        }
 private string GetId(Feature feature)
 {
     return feature.Geometry.GeometryType + "_" + feature.Attributes["osm_id"];
 }