Giter VIP home page Giter VIP logo

Comments (3)

maruhe avatar maruhe commented on August 17, 2024 1

sometimes I have to write a quistion to find the answer ;-)
I got happy by finding NetTopologySuite using GeoJSON.NET parser:

here my sample so the next one may can find it faster:

            using GeoJSON.Net;
            using GeoJSON.Net.Feature;
            using NetTopologySuite.Geometries;

            string topology_string = File.ReadAllText("ne_10m_time_zones.geojson"));

            // create NetTopology JSON reader
            var reader = new NetTopologySuite.IO.GeoJsonReader();

            // pass geoJson's FeatureCollection to read all the features
            var featureCollection = reader.Read<GeoJSON.Net.Feature.FeatureCollection>(topology_string);

            // if feature collection is null then return 
            if (featureCollection == null)
            {
                return;
            }

            // loop through all the parsed featurd   
            for (int featureIndex = 0;
                 featureIndex < featureCollection.Features.Count;
                 featureIndex++)
            {
                // get json feature
                var jsonFeature = featureCollection.Features[featureIndex];
                Geometry geom = null;

                // get geometry type to create appropriate geometry
                switch (jsonFeature.Geometry.Type)
                {
                    case GeoJSONObjectType.Point:
                        break;
                    case GeoJSONObjectType.MultiPoint:
                        break;
                    case GeoJSONObjectType.LineString:
                        break;
                    case GeoJSONObjectType.MultiLineString:
                        break;
                    case GeoJSONObjectType.Polygon:
                        {
                            var polygon = jsonFeature.Geometry as GeoJSON.Net.Geometry.Polygon;

                            List<Coordinate> coordinates = new List<Coordinate>();
                            foreach (var ring in polygon.Coordinates)
                            {
                                if (ring.IsLinearRing())
                                {
                                    foreach (var coordinate in ring.Coordinates)
                                    {
                                        coordinates.Add(new Coordinate(coordinate.Latitude, coordinate.Longitude));
                                    }
                                }
                            }
                            //Add first Point again to be sure to have a closed Polygon
                            //may you have to remove this line:
                            coordinates.Add(new Coordinate(coordinates[0].X, coordinates[0].Y));

                            var poly = new Polygon(new LinearRing(coordinates.ToArray()));
                            if (poly.Contains(new Point(x, y))
                                FounTimeZoneForPoint();
                        }
                        break;
                    case GeoJSONObjectType.MultiPolygon:
                        break;
                    case GeoJSONObjectType.GeometryCollection:
                        break;
                    case GeoJSONObjectType.Feature:
                        break;
                    case GeoJSONObjectType.FeatureCollection:
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

and sure, please close it again, you guys did a great work!

from geojson.net.

xfischer avatar xfischer commented on August 17, 2024

Hi @maruhe. Thanks for reaching out. There is no stupid question. You just need guidance.

GeoJSON is only a parser and a simple type library to have typed GeoJson classes in .Net. Very handful when you have a geoJson as plain text and need to have its counterpart in .net, and vice-versa.

What you are trying to do is perform spatial operations on the GeoJson, and this is not the purpose of the library.
That said, you're left with alternatives:

  1. Move to more "spatial" libraries (NetTopology, DotSpatial, ...). They can read GeoJson and then you can perform almost any computations you'll like.
  2. Code your point in polygon routine (not recommended, spatial operations are hard on spherical data, and the work has been done already)

I'm closing the issue, feel free to comment if you need more information.

from geojson.net.

xfischer avatar xfischer commented on August 17, 2024

Happy to see that you've found a way around, @maruhe! Thanks!

from geojson.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.