Skip to content

Commit

Permalink
Add docs on constraining spatial columns
Browse files Browse the repository at this point in the history
See #719
  • Loading branch information
roji committed Dec 13, 2018
1 parent 53f499c commit d5fc5e3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/mapping/nts.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public class City
var nearbyCities = context.Cities.Where(c => c.Location.Distance(somePoint) < 100);
```

## Constraining your type names

With the code above, the provider will create a database column of type `geometry`. This is perfectly fine, but be aware that this type accepts any geometry type (point, polygon...), with any coordinate system (XY, XYZ...). It's good practice to constrain the column to the exact type of data you will be storing, but unfortunately the provider isn't aware of your required coordinate system and therefore can't do that for you. Consider explicitly specifying your column types on your properties as follows:

```c#
[Column(TypeName="geometry (point)")]
public Point Location { get; set; }
```

This will constrain your column to XY points only. The same can be done via the fluent API with `HasColumnType()`.

## Operation translation

The following table lists NetTopologySuite operations which are translated to PostGIS SQL operations. This allows you to use these NetTopologySuite methods and members efficiently - evaluation will happen on the server side. Since evaluation happens at the server, table data doesn't need to be transferred to the client (saving bandwidth), and in some cases indexes can be used to speed things up.
Expand Down Expand Up @@ -94,7 +105,7 @@ The Npgsql provider will be default map all NetTopologySuite types to PostGIS `g
```c#
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<City>().Property(b => b.Location).HasColumnType("geography");
builder.Entity<City>().Property(b => b.Location).HasColumnType("geography (point)");
}
```

Expand Down

0 comments on commit d5fc5e3

Please sign in to comment.