Skip to content

Commit

Permalink
Updated Spatial Demos (#2667)
Browse files Browse the repository at this point in the history
Co-authored-by: steveoh <sgourley@utah.gov>
  • Loading branch information
PascalSenn and steveoh committed Nov 30, 2020
1 parent c58d11d commit 811b6b5
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 96 deletions.
Expand Up @@ -13,70 +13,151 @@ public class ApplicationDbContext : DbContext
protected override void OnModelCreating(
ModelBuilder modelBuilder)
{
modelBuilder.Entity<County>(
modelBuilder.Entity<Parcel>(
entity =>
{
entity.HasKey(e => e.Xid)
.HasName("county_boundaries_pkey");
.HasName("salt_lake_county_parcels_lir_pkey");
entity.ToTable("county_boundaries", "boundaries");
entity.ToTable("salt_lake_county_parcels_lir", "cadastre");
entity.HasIndex(e => e.Shape)
.HasName("county_boundaries_shape_geom_idx")
.HasDatabaseName("salt_lake_county_parcels_lir_shape_geom_idx")
.HasMethod("gist");
entity.Property(e => e.Xid).HasColumnName("xid");
entity.Property(e => e.Color4)
.HasColumnName("color4")
.HasColumnType("numeric(5,0)");
entity.Property(e => e.Countynbr)
.HasColumnName("countynbr")
.HasMaxLength(2);
entity.Property(e => e.Entitynbr)
.HasColumnName("entitynbr")
.HasColumnType("numeric(38,8)");
entity.Property(e => e.ParcelId)
.HasColumnName("parcel_id")
.HasMaxLength(50);
entity.Property(e => e.Entityyr)
.HasColumnName("entityyr")
entity.Property(e => e.BuildingSqFt)
.HasColumnName("bldg_sqft")
.HasColumnType("numeric(38,8)");
entity.Property(e => e.Fips)
.HasColumnName("fips")
entity.Property(e => e.Floors)
.HasColumnName("floors_cnt")
.HasColumnType("numeric(38,8)");
entity.Property(e => e.FipsStr)
.HasColumnName("fips_str")
.HasMaxLength(5);
entity.Property(e => e.RoomCount)
.HasColumnName("house_cnt")
.HasMaxLength(10);
entity.Property(e => e.Name)
.HasColumnName("name")
.HasMaxLength(100);
entity.Property(e => e.PopCurrestimate)
.HasColumnName("pop_currestimate")
.HasColumnType("numeric(10,0)");
entity.Property(e => e.MarketValue)
.HasColumnName("total_mkt_value")
.HasColumnType("numeric(38,8)");
entity.Property(e => e.PopLastcensus)
.HasColumnName("pop_lastcensus")
.HasColumnType("numeric(10,0)");
entity.Property(e => e.YearBuilt)
.HasColumnName("built_yr")
.HasColumnType("numeric(5,0)");
entity.Property(e => e.Shape)
.HasColumnName("shape")
.HasColumnType("geometry(MultiPolygon,26912)");
entity.Property(e => e.Stateplane)
.HasColumnName("stateplane")
.HasMaxLength(20);
entity.Property(e => e.Shape)
.HasColumnName("shape")
.HasColumnType("geometry");
});

modelBuilder.Entity<LiquorStore>(
entity => {
entity.HasKey(e => e.Xid)
.HasName("liquor_stores_pkey");
entity.ToTable("liquor_stores", "society");
entity.HasIndex(e => e.Shape)
.HasDatabaseName("liquor_stores_shape_geom_idx")
.HasMethod("gist");
entity.Property(e => e.Xid).HasColumnName("xid");
entity.Property(e => e.Shape)
.HasColumnName("shape")
.HasColumnType("geometry");
entity.Property(e => e.Shape)
.HasColumnName("shape")
.HasColumnType("geometry(Point,26912)");
entity.Property(e => e.StoreNumber)
.HasColumnName("storenumber")
.HasColumnType("numeric(5,0)");
entity.Property(e => e.Zip)
.HasColumnName("zip")
.HasColumnType("numeric(10,0)");
entity.Property(e => e.Name)
.HasColumnName("name")
.HasMaxLength(50);
entity.Property(e => e.Type)
.HasColumnName("type")
.HasMaxLength(20);
entity.Property(e => e.Address)
.HasColumnName("address")
.HasMaxLength(50);
entity.Property(e => e.City)
.HasColumnName("city")
.HasMaxLength(35);
entity.Property(e => e.County)
.HasColumnName("county")
.HasMaxLength(25);
entity.Property(e => e.Phone)
.HasColumnName("phone")
.HasMaxLength(15);
});
modelBuilder.Entity<GolfCourse>(
entity => {
entity.HasKey(e => e.Xid)
.HasName("golf_courses_pkey");
entity.ToTable("golf_courses", "recreation");
entity.HasIndex(e => e.Shape)
.HasDatabaseName("golf_courses_shape_geom_idx")
.HasMethod("gist");
entity.Property(e => e.Xid).HasColumnName("xid");
entity.Property(e => e.Shape)
.HasColumnName("shape")
.HasColumnType("geometry");
entity.Property(e => e.Shape)
.HasColumnName("shape")
.HasColumnType("geometry(MultiPolygon,26912)");
entity.Property(e => e.Par)
.HasColumnName("par")
.HasColumnType("numeric(10,0)");
entity.Property(e => e.Holes)
.HasColumnName("holes")
.HasColumnType("numeric(10,0)");
entity.Property(e => e.Name)
.HasColumnName("name")
.HasMaxLength(50);
entity.Property(e => e.City)
.HasColumnName("city")
.HasMaxLength(30);
entity.Property(e => e.County)
.HasColumnName("county")
.HasMaxLength(30);
});
}

public DbSet<County> Counties { get; set; } = default!;
public DbSet<Parcel> Parcels { get; set; } = default!;
public DbSet<LiquorStore> LiquorStores { get; set; } = default!;
public DbSet<GolfCourse> GolfCourses { get; set; } = default!;
}
}
31 changes: 0 additions & 31 deletions src/HotChocolate/Spatial/demo/Spatial.Demo/Database/County.cs

This file was deleted.

13 changes: 13 additions & 0 deletions src/HotChocolate/Spatial/demo/Spatial.Demo/Database/GolfCourse.cs
@@ -0,0 +1,13 @@
using NetTopologySuite.Geometries;

namespace Spatial.Demo {
public class GolfCourse {
public int Xid { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string County { get; set; }
public int Par { get; set; }
public int Holes { get; set; }
public MultiPolygon Shape { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/HotChocolate/Spatial/demo/Spatial.Demo/Database/LiquorStore.cs
@@ -0,0 +1,16 @@
using NetTopologySuite.Geometries;

namespace Spatial.Demo {
public class LiquorStore {
public int Xid { get; set; }
public int StoreNumber { get; set; }
public string Type { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string County { get; set; }
public string Phone { get; set; }
public int Zip { get; set; }
public Point Shape { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/HotChocolate/Spatial/demo/Spatial.Demo/Database/Parcel.cs
@@ -0,0 +1,16 @@
using NetTopologySuite.Geometries;

namespace Spatial.Demo
{
public class Parcel
{
public int Xid { get; set; }
public string ParcelId { get; set; }
public int BuildingSqFt { get; set; }
public int Floors { get; set; }
public string RoomCount { get; set; }
public decimal? MarketValue { get; set; }
public int YearBuilt { get; set; }
public MultiPolygon Shape { get; set; }
}
}
19 changes: 17 additions & 2 deletions src/HotChocolate/Spatial/demo/Spatial.Demo/Schema/Query.cs
Expand Up @@ -7,9 +7,24 @@ namespace Spatial.Demo
public class Query
{
[UseDbContext(typeof(ApplicationDbContext))]
[UseProjection]
[UseFiltering]
public IQueryable<County> GetCounties(
public IQueryable<Parcel> GetParcels(
[ScopedService] ApplicationDbContext context) =>
context.Counties;
context.Parcels;

[UseDbContext(typeof(ApplicationDbContext))]
[UseProjection]
[UseFiltering]
public IQueryable<LiquorStore> GetLiquorStores(
[ScopedService] ApplicationDbContext context) =>
context.LiquorStores;

[UseDbContext(typeof(ApplicationDbContext))]
[UseProjection]
[UseFiltering]
public IQueryable<GolfCourse> GetGolfCourses(
[ScopedService] ApplicationDbContext context) =>
context.GolfCourses;
}
}
Expand Up @@ -8,8 +8,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="3.1.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="5.0.0" />
</ItemGroup>

<PropertyGroup>
Expand Down
34 changes: 10 additions & 24 deletions src/HotChocolate/Spatial/demo/Spatial.Demo/Startup.cs
@@ -1,44 +1,30 @@
using System;
using HotChocolate;
using HotChocolate.Data.Filters;
using HotChocolate.Data.Filters.Expressions;
using HotChocolate.Data.Filters;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Spatial.Demo
{
public class Startup
{
public static readonly ILoggerFactory loggerFactory =
LoggerFactory.Create(x => x.AddConsole());

private const string connectionString =
private const string CONNECTION_STRING =
"Database=opensgid;Host=opensgid.agrc.utah.gov;Username=agrc;Password=agrc";

public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<ApplicationDbContext>(
options =>
options.UseNpgsql(
connectionString,
o =>
o.UseNetTopologySuite())
.UseLoggerFactory(loggerFactory)
)
services.AddPooledDbContextFactory<ApplicationDbContext>(
options => options
.UseNpgsql(CONNECTION_STRING, o => o.UseNetTopologySuite())
.LogTo(Console.WriteLine))
.AddGraphQLServer()
.AddFiltering()
.AddProjections()
.AddSpatialTypes()
.AddFiltering(
x => x
.AddDefaults()
.AddSpatialOperations()
.BindSpatialTypes()
.Provider(
new QueryableFilterProvider(
p => p.AddSpatialHandlers().AddDefaultFieldHandlers())))
.AddSpatialProjections()
.AddSpatialFiltering()
.AddQueryType<Query>();
}

Expand Down

0 comments on commit 811b6b5

Please sign in to comment.