Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return data frame if no spatial data available in import_from_gis() (v0.2.5) #71

Conversation

eroten
Copy link
Collaborator

@eroten eroten commented Dec 22, 2023

Implement conditional when pulling tables from GISLibrary

import_from_gis() now pulls the query table column information and checks for any "geometry" data types.
If there is a geometry column, pull table and return as sf object.
If there is no geometry, pull table and return as data frame.

This fix isn't absolutely necessary - we could just update the documentation to show an example of pulling a non-spatial table using gis_connection().

Additional changes

  • Update tests
  • Increment version, date
  • No new dependencies
  • Fix typos

Closes #70

Remedied reprex

library(councilR)

options(councilR.uid = "mc\\rotenle",
        councilR.pwd = keyring::key_get("MetC"))

tracts2010_spatial <- import_from_gis(
  query = "GISLibrary.dbo.Census2010TigerTract",
  .quiet = TRUE
)

# output truncated
head(tracts2010_spatial)
#> Simple feature collection with 6 features and 15 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: 458704.8 ymin: 4947713 xmax: 510796.5 ymax: 4996701
#> Projected CRS: NAD83 / UTM zone 15N
#>   OBJECTID STATEFP10 COUNTYFP10 TRACTCE10     GEOID10 NAME10
#> 1        1        27        037    060744 27037060744 607.44
#> 2        2        27        139    080903 27139080903 809.03
#> 3        3        27        037    060738 27037060738 607.38
#> 4        4        27        123    034602 27123034602 346.02
#> 5        5        27        163    070403 27163070403 704.03
#> 6        6        27        163    070909 27163070909 709.09
#>            NAMELSAD10 MTFCC10 FUNCSTAT10  ALAND10 AWATER10  INTPTLAT10
#> 1 Census Tract 607.44   G5020          S  2053432    86758 +44.7861609
#> 2 Census Tract 809.03   G5020          S 28332969  4533634 +44.7225340
#> 3 Census Tract 607.38   G5020          S  2128920    26061 +44.7735895
#> 4 Census Tract 346.02   G5020          S  1572097        0 +44.9570359
#> 5 Census Tract 704.03   G5020          S 63302121  3042082 +45.0743811
#> 6 Census Tract 709.09   G5020          S  4196628    25974 +44.9792561
#>                              wkt
#> 1 POLYGON ((481983.3 4959679,...
#> 2 MULTIPOLYGON (((458707 4947...
#> 3 POLYGON ((479657.5 4956868,...
#> 4 POLYGON ((496397.8 4978603,...
#> 5 POLYGON ((504360 4987370, 5...
#> 6 POLYGON ((504423.9 4980078,...

tracts2010_popHH <- import_from_gis(
  query = "GISLibrary.dbo.Census2010PopulationTract",
  .quiet = TRUE
)

head(tracts2010_popHH)
# output truncated
#>   OBJECTID   GEOG_UNIT GEOG_LEVEL              GEONAME              GEOID
#> 1        1 27001770100      TRACT    Census Tract 7701 14000US27001770100
#> 2        2 27001770200      TRACT    Census Tract 7702 14000US27001770200
#> 3        3 27001770300      TRACT    Census Tract 7703 14000US27001770300
#> 4        4 27001770400      TRACT    Census Tract 7704 14000US27001770400
#> 5        5 27001790501      TRACT Census Tract 7905.01 14000US27001790501
#> 6        6 27001790502      TRACT Census Tract 7905.02 14000US27001790502

Created on 2023-12-22 with reprex v2.0.2

@eroten eroten added the bug Something isn't working label Dec 22, 2023
@eroten eroten self-assigned this Dec 22, 2023
@eroten eroten requested a review from LimerickSam December 22, 2023 21:57
Copy link
Collaborator

@LimerickSam LimerickSam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for doing this! I think it will make getting access to "gold standard" versions of commonly used datasets so much faster (and less prone to user error from managing separate joins/joining from diff data sources with diff CRS, etc.)

@LimerickSam LimerickSam merged commit e620aeb into main Jan 2, 2024
2 checks passed
@LimerickSam LimerickSam deleted the 70-add-helper-for-connecting-to-enterprise-geodatabase-tables-in-databases-vignette branch January 2, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add helper for connecting to enterprise geodatabase tables in Databases vignette
2 participants