0

I have a individual land price data, and I am trying to get the flood hazard zone category using the flood hazard zone shape file (link here https://files.hawaii.gov/dbedt/op/gis/data/s_fld_haz_ar_state.zip) in R. The first 5 sample of land price data (from shapefile) is in the link below: https://drive.google.com/file/d/1HSN9e48CncqV0IRDqx41Ubf3fazhB-ey/view (I can't dput here because of limitation on characters of the question) .

    library(sf)
    flood_zone_sf<-read_sf("s_fld_haz_ar_state.shp")
 # the variable I am interested is FLD_ZONE. 
flood_zone_sf

flood_zone_sf
Simple feature collection with 14676 features and 21 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -160.2471 ymin: 18.90852 xmax: -154.8049 ymax: 22.23527
Geodetic CRS:  WGS 84 (with axis order normalized for visualization)
First 10 features:
   DFIRM_ID VERSION_ID FLD_AR_ID STUDY_TYP FLD_ZONE ZONE_SUBTY SFHA_TF STATIC_BFE V_DATUM DEPTH LEN_UNIT VELOCITY VEL_UNIT AR_REVERT AR_SUBTRV BFE_REVERT DEP_REVERT DUAL_ZONE    SOURCE_CIT Shape_Leng Shape_Area
1    15001C    1.1.1.0  15001C_1        NP       AE       <NA>       T         19     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA>   15001C_FIS1  1021.7487  10228.030
2    15001C    1.1.1.0  15001C_2        NP       AE       <NA>       T         10     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6   396.2263   3168.708
3    15001C    1.1.1.0  15001C_3        NP       AE       <NA>       T      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA>   15001C_FIS1  1652.8730  56536.222
4    15001C    1.1.1.0  15001C_4        NP       VE       <NA>       T         46     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6   883.2431  47108.242
5    15001C    1.1.1.0  15001C_5        NP       VE       <NA>       T         22     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6  1975.2465 157356.794
6    15001C    1.1.1.0  15001C_6        NP       VE       <NA>       T         14     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6   963.0295  53570.545
7    15001C    1.1.1.0  15001C_7        NP       VE       <NA>       T         26     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6  1066.6585  63543.361
8    15001C    1.1.1.0  15001C_8        NP       VE       <NA>       T         42     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6   912.4932  49507.926
9    15001C    1.1.1.0  15001C_9        NP       VE       <NA>       T         26     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6  1300.7773  93243.093
10   15001C    1.1.1.0 15001C_10        NP       VE       <NA>       T         10     MSL -9999     Feet    -9999     <NA>      <NA>      <NA>      -9999      -9999      <NA> 15001C_STUDY6  1715.9454 161528.883
                         geometry
1  POLYGON ((-155.6412 18.9361...
2  POLYGON ((-155.7276 18.9674...
3  POLYGON ((-155.6204 18.9688...
4  POLYGON ((-155.5913 18.9951...
5  POLYGON ((-155.5861 18.9999...
6  POLYGON ((-155.585 19.00383...
7  POLYGON ((-155.5841 19.0064...
8  POLYGON ((-155.5826 19.0054...
9  POLYGON ((-155.5823 19.0115...
10 POLYGON ((-155.5781 19.0169...

land_data_sf
   

     Simple feature collection with 5 features and 1 field
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -157.9444 ymin: 21.33355 xmax: -157.9072 ymax: 21.3442
Geodetic CRS:  WGS 84
  meansaleprice                       geometry
1        415000 MULTIPOLYGON (((-157.9414 2...
2        415000 MULTIPOLYGON (((-157.9414 2...
3       5228200 MULTIPOLYGON (((-157.9072 2...
4       5228200 MULTIPOLYGON (((-157.9072 2...
5       5228200 MULTIPOLYGON (((-157.9072 2...

How do I extract FLD_ZONE from flood hazard zone shapefile for the land price shapefile using R?

I have used st_join but I am getting error.

st_join(jj,flood_zone_sf)
Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented,  : 
  Loop 0 is not valid: Edge 4851 has duplicate vertex with edge 5006

1 Answer 1

1

Not sure where jj is coming from, but the error message is quite explicit about geometry issues, which you can check and solve using {sf}.

Out of 14,676 objects of s_fld_haz_ar_state.shp, 36 objects seem to have invalid geometry:

library(sf)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE

# import shp
flood_zone_sf <- read_sf("s_fld_haz_ar_state.shp") 

# get number of objects
dim(flood_zone_sf)[1]
#> [1] 14676

# check for geometry issues
st_is_valid(flood_zone_sf) |> sum()
#> [1] 14640

From my point of view, you can solve this quite easily via st_make_valid() and continue with st_join() after harmonizing coordinate reference systems in order to join the attributes of flood_zone_sf on land_price_sf based on geometry information:

st_crs(land_price_sf)$epsg
#> [1] 4326

# reproject and make valid
flood_zone_sf <- flood_zone_sf |> sf::st_transform("epsg:4326") |> sf::st_make_valid()

# spatial join
lpfz_sf <- sf::st_join(land_price_sf, flood_zone_sf)

head(lpfz_sf)
#> Simple feature collection with 6 features and 22 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -157.9444 ymin: 21.33355 xmax: -157.9072 ymax: 21.3442
#> Geodetic CRS:  WGS 84
#>     meansaleprice DFIRM_ID VERSION_ID   FLD_AR_ID STUDY_TYP FLD_ZONE ZONE_SUBTY
#> 1          415000   15003C    1.1.1.0   15003C_43        NP        D       <NA>
#> 1.1        415000   15003C    1.1.1.0 15003C_1250        NP        D       <NA>
#> 2          415000   15003C    1.1.1.0   15003C_43        NP        D       <NA>
#> 2.1        415000   15003C    1.1.1.0 15003C_1250        NP        D       <NA>
#> 3         5228200   15003C    1.1.1.0 15003C_1250        NP        D       <NA>
#> 4         5228200   15003C    1.1.1.0 15003C_1250        NP        D       <NA>
#>     SFHA_TF STATIC_BFE V_DATUM DEPTH LEN_UNIT VELOCITY VEL_UNIT AR_REVERT
#> 1         F      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>
#> 1.1       F      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>
#> 2         F      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>
#> 2.1       F      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>
#> 3         F      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>
#> 4         F      -9999    <NA> -9999     <NA>    -9999     <NA>      <NA>
#>     AR_SUBTRV BFE_REVERT DEP_REVERT DUAL_ZONE  SOURCE_CIT Shape_Leng Shape_Area
#> 1        <NA>      -9999      -9999      <NA> 15003C_FIS1   21527.26    5408537
#> 1.1      <NA>      -9999      -9999      <NA>          NP   46849.28   20547349
#> 2        <NA>      -9999      -9999      <NA> 15003C_FIS1   21527.26    5408537
#> 2.1      <NA>      -9999      -9999      <NA>          NP   46849.28   20547349
#> 3        <NA>      -9999      -9999      <NA>          NP   46849.28   20547349
#> 4        <NA>      -9999      -9999      <NA>          NP   46849.28   20547349
#>                           geometry
#> 1   MULTIPOLYGON (((-157.9414 2...
#> 1.1 MULTIPOLYGON (((-157.9414 2...
#> 2   MULTIPOLYGON (((-157.9414 2...
#> 2.1 MULTIPOLYGON (((-157.9414 2...
#> 3   MULTIPOLYGON (((-157.9072 2...
#> 4   MULTIPOLYGON (((-157.9072 2...
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.