Comments (3)
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.
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:
- Move to more "spatial" libraries (NetTopology, DotSpatial, ...). They can read GeoJson and then you can perform almost any computations you'll like.
- 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.
Happy to see that you've found a way around, @maruhe! Thanks!
from geojson.net.
Related Issues (20)
- Cannot use GeoJson.Net.Exceptions HOT 2
- .net core api does not deserialize correctly with default System.Text.Json library HOT 1
- How to get the area of a geometry? HOT 4
- Move serializers to a separate project and NuGet to support System.Text.Json in another project and NuGet HOT 5
- PolygonEnumerableConverter does not work HOT 2
- The library might not be aligned with the GeoJSON RFC 7946 standard HOT 3
- How to add altitude coordinates in Feature Collection then serialize to GeoJson
- Geometry is readonly HOT 4
- Incorrectly coupling to geographic coordinate systems HOT 4
- Target frameworks: why so many? HOT 3
- The supported version of the dependency Newtonsoft.Json has a High Severity Vulnerability. HOT 4
- Function to calculate the new coordinates from given base coordinates, along with a distance & a bearing? HOT 2
- Should `IGeometryObject` expose bounding box and CRS?
- Properties in root HOT 1
- Access all fields including Contexts
- NuGet stable release HOT 7
- Coordinates type doesn't parse properties HOT 3
- `CRS` member is no longer used (as per RFC)
- Get Feature Properties from inheritance object HOT 3
- There is a problem getting the value of type HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geojson.net.