yonghah/esri2sf

Feature idea: make fromJSON call into getmeta function to return ESRI layer metadata

elipousson opened this issue · 0 comments

I recently realized that the ESRI FeatureServer and MapServer metadata occasionally includes alias names for the fields that can include helpful explanatory information that may not be clear based on the original column names alone.

I think it could be helpful to take the fromJSON call that appears in both esri2sf and esri2df and turn it into a public function (I thought esrimeta seemed consistent with the other function names but I'm happy for better options) that allows users to return all layer info or return the fields alone. Let me know if this idea seems like a good addition to the package and I'd be happy to make a pull request. I included an example MapServer layer below that shows how field aliases may be used.

esrimeta <- function(url, token = "", fields = FALSE) {
  layerInfo <- jsonlite::fromJSON(
    httr::content(
      httr::POST(
        url,
        query = list(f = "json", token = token),
        encode = "form",
        config = httr::config(ssl_verifypeer = FALSE)
      ),
      as = "text"
    )
  )

  if (fields) {
    return(layerInfo$fields)
  } else {
    return(layerInfo)
  }
}

url <- "https://maps2.dcgis.dc.gov/dcgis/rest/services/DCOZ/Zone_Mapservice/MapServer/13"

esrimeta("https://maps2.dcgis.dc.gov/dcgis/rest/services/DCOZ/Zone_Mapservice/MapServer/13", fields = TRUE)