Guest User

Untitled

a guest
Apr 7th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. from arcgis.gis import GIS
  2. from arcgis.features import Feature, FeatureCollection, FeatureLayer, FeatureSet
  3. from arcgis.features.use_proximity import find_nearest
  4. from arcgis.geocoding import Geocoder
  5. import logging, os, requests
  6.  
  7.  
  8. def _get_open_spaces():
  9. """
  10. Gets the open spaces from the City's MapServer
  11. """
  12. open_spaces_url = "http://gis.cityofboston.gov/arcgis/rest/"
  13. + "services/EnvironmentEnergy/OpenData/MapServer/7"
  14. f = FeatureLayer(url = open_spaces_url)
  15. return f
  16.  
  17.  
  18. if __name__ == "__main__":
  19. username = ************
  20. passwrd = *************
  21. log_filename = "log/open_spaces_log"
  22. try:
  23. os.remove(log_filename)
  24. except OSError:
  25. pass
  26. logging.basicConfig(filename=log_filename, level=logging.DEBUG)
  27. my_address = "94 Sawyer Ave., Boston, MA, 02125"
  28. g = GIS(username = username, password=passwrd)
  29. logging.debug("Using address: %s" % my_address)
  30. logging.debug("getting open spaces feature layer")
  31. near_layer = _get_open_spaces()
  32. assert near_layer, "something went wrong with the near_layer"
  33. logging.debug("now we're trying to get the address into its on feature_layer")
  34. coded_address = Geocoder(my_address, g)
  35. address_as_feature = Feature('point', coded_address)
  36. analysis_layer = FeatureCollection(address_as_feature.as_dict)
  37. find_nearest(analysis_layer, near_layer)
Add Comment
Please, Sign In to add comment