Example #1
0
def get_data_slice(base_url,
                   service_url,
                   layer,
                   tenure_list,
                   tenure_filter_col,
                   out_cols=None):

    ags = restapi.ArcServer(base_url)
    if not out_cols:
        out_cols = "*"

    try:
        query = tenure_filter_col + " IN (" + ','.join(
            [str(int(t)) for t in tenure_list]) + ")"
    except ValueError:
        query = tenure_filter_col + " IN (" + ','.join(
            ["'" + str(t) + "'" for t in tenure_list]) + ")"

    extension = service_url.split('/')[-1]
    if extension == 'MapServer':
        svc = restapi.MapService(service_url, token=ags.token)
    elif extension == 'FeatureServer':
        svc = restapi.FeatureService(service_url, token=ags.token)
    elif extension == 'GPServer':
        svc = restapi.GPService(service_url, token=ags.token)
    elif extension == 'ImageServer':
        svc = restapi.ImageService(service_url, token=ags.token)
    elif extension == 'GeocodeServer':
        svc = restapi.Geocoder(service_url, token=ags.token)
    else:
        raise NotImplementedError('restapi does not support "{}" services!')

    lyr = svc.layer(layer)
    result = lyr.query(query, out_cols)

    out_data = [r["properties"] for r in result]

    return out_data
Example #2
0
esri_json = {"rings":[[[-121.5,38.6],[-121.4,38.6],
                      [-121.3,38.6],[-121.2,38.6],
                      [-121.2,38.3],[-121.5,38.3],
                      [-121.5,38.6]]],
            "spatialReference":
                {"wkid":4326,"latestWkid":4326}}

# clip by polygon and filter fields (can use polygon shapefile or feature class as well)
sac = os.path.join(folder, 'Sacramento_gauges.shp')
lyr.clip(esri_json, sac, fields=['gaugelid', 'location'])

#----------------------------------------------------------------------------------------------------#
# Geocoding examples
# hennepin county, MN geocoder
henn = 'http://gis.hennepin.us/arcgis/rest/services/Locators/HC_COMPOSITE/GeocodeServer'
geocoder = restapi.Geocoder(henn)
# find target field, use the SingleLine address field by default
geoResult = geocoder.findAddressCandidates('353 N 5th St, Minneapolis, MN 55403')

# export results to shapefile
print 'found {} candidates'.format(len(geoResult))
geocoder.exportResults(geoResult, os.path.join(folder, 'target_field.shp'))

# Esri geocoder
esri_url = 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer'
esri_geocoder = restapi.Geocoder(esri_url)

# find candidates using key word arguments (**kwargs) to fill in locator fields, no single line option
candidates = esri_geocoder.findAddressCandidates(Address='380 New York Street', City='Redlands', State='CA', Zip='92373')
print 'Number of address candidates: {}'.format(len(candidates))
for candidate in candidates:
Example #3
0
import os
import arcpy
import json
from collections import namedtuple
import restapi
#from . import restapi
from . import requests
from .strings import *

ramsey_gc = restapi.Geocoder(RAMSEY_GC)

def geocode_address(address, outSR=RAMSEY_WKID):
    """geocodes an address, tries Ramsey County geocoder first, if no good results then try google"""
    gcr = ramsey_gc.findAddressCandidates(address, outSR=outSR)
    if gcr:
        pt = gcr[0].location
        return arcpy.PointGeometry(arcpy.Point(pt['x'], pt['y']), arcpy.SpatialReference(outSR))

    else:
        # try google
        if not 'maplewood' in address.lower():
            address += ' maplewood, mn 55109'

        r = googleGC(address)
        loc = r.location
        if loc['x'] is not None:
            pt_wgs = arcpy.PointGeometry(arcpy.Point(loc['x'], loc['y']), arcpy.SpatialReference(4326))
            return pt_wgs.projectAs(arcpy.SpatialReference(outSR))

    return None