-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- (Json.NET): replaced usage of the serializer context - (Json.NET): treat "coordinates":null and "geometries":null as empty - (STJ): emit "coordinates":[] instead of "coordinates":null for empty, for better interoperability
- Loading branch information
Showing
9 changed files
with
163 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,52 @@ | ||
# GeoJSON | ||
|
||
GeoJSON IO module for NTS. | ||
|
||
## GeoJSON4STJ Usage | ||
|
||
This is the package for System.Text.Json serialization and deserialization. | ||
|
||
### ASP.NET Core Example | ||
|
||
Add the `System.Text.Json.Serializer.JsonConverterFactory`, `GeoJsonConverterFactory`, to the `JsonSerializerOptions` when you configure your controllers, MVC, etc in the `ConfigureServices` method of your `Startup.cs` class. | ||
|
||
```csharp | ||
public void ConfigureServices(IServiceCollection services) { | ||
services.AddControllers() | ||
.AddJsonOptions(options => { | ||
options.JsonSerializerOptions.Converters.Add(new NetTopologySuite.IO.Converters.GeoJsonConverterFactory()); | ||
}); | ||
} | ||
```` | ||
|
||
## GeoJSON Usage | ||
|
||
**GeoJSON to `Geometry`**: | ||
|
||
```c# | ||
var geoJson = "{\"type\":\"Point\",\"coordinates\":[0.0,0.0]}"; | ||
Geometry geometry; | ||
|
||
var serializer = GeoJsonSerializer.Create(); | ||
using (var stringReader = new StringReader(geoJson)) | ||
using (var jsonReader = new JsonTextReader(stringReader)) | ||
{ | ||
geometry = serializer.Deserialize<Geometry>(jsonReader); | ||
} | ||
``` | ||
|
||
**`Geometry` to GeoJSON**: | ||
|
||
```c# | ||
var geometry = new Point(0, 0); | ||
string geoJson; | ||
|
||
var serializer = GeoJsonSerializer.Create(); | ||
using (var stringWriter = new StringWriter()) | ||
using (var jsonWriter = new JsonTextWriter(stringWriter)) | ||
{ | ||
serializer.Serialize(jsonWriter, geometry); | ||
geoJson = stringWriter.ToString(); | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters