Exemple #1
0
 def __init__(self,outFile,featureClass,fileType,includeGeometry, first=True, outName=False):
     self.outFile = outFile
     self.fileType = fileType
     #first we set put the local variables we'll need
     [self.shp,self.shpType]=getShp(featureClass)
     self.fields=listFields(featureClass)
     self.oid=getOID(self.fields)
     sr=SpatialReference()
     sr.loadFromString(wgs84)
     #the search cursor
     self.rows=SearchCursor(featureClass,"",sr)
     #don't want the shape field showing up as a property
     del self.fields[self.shp]
     self.first=first
     self.status = statusMessage(featureClass)
     #define the correct geometry function if we're exporting geometry
     self.parseGeo = getParseFunc(self.shpType,includeGeometry)
     self.i=0
     if fileType=="geojson":
         self.parse = self.parseGeoJSON_ElasticSearch
     elif fileType=="csv":
         self.parse = self.parseCSV
     elif fileType=="json":
         self.parse = self.parseJSON
     elif fileType=="sqlite":
         self.parse = self.parseSqlite
     elif fileType=="topojson":
         self.parse = self.parseTOPOJSON
         if outName:
             self.oName=outName
         else:
             self.oName = getName(featureClass)
         self.topo = self.outFile['topo'].object_factory(self.oName)
Exemple #2
0
 def __init__(self,
              outFile,
              featureClass,
              fileType,
              includeGeometry,
              first=True):
     self.outFile = outFile
     self.fileType = fileType
     #first we set put the local variables we'll need
     [self.shp, self.shpType] = getShp(featureClass)
     self.fields = listFields(featureClass)
     self.oid = getOID(self.fields)
     sr = SpatialReference()
     sr.loadFromString(wgs84)
     #the search cursor
     self.rows = SearchCursor(featureClass, "", sr)
     #don't want the shape field showing up as a property
     del self.fields[self.shp]
     self.first = first
     self.status = statusMessage(featureClass)
     #define the correct geometry function if we're exporting geometry
     self.parseGeo = getParseFunc(self.shpType, includeGeometry)
     self.i = 0
     if fileType == "geojson":
         self.parse = self.parseGeoJSON
     elif fileType == "csv":
         self.parse = self.parseCSV
     elif fileType == "json":
         self.parse = self.parseJSON
     elif fileType == "sqlite":
         self.parse = self.parseSqlite
Exemple #3
0
 def test_init_with_coordinate_system_does_not_change(self):
     crate = Crate('foo', 'bar', 'baz', 'qux', SpatialReference(26921))
     self.assertEqual(crate.source_name, 'foo')
     self.assertEqual(crate.source_workspace, 'bar')
     self.assertEqual(crate.destination_workspace, 'baz')
     self.assertEqual(crate.destination_name, 'qux')
     self.assertIsInstance(crate.destination_coordinate_system, SpatialReference)
def create_isochrone_fc():
    """Create a new feature class to store all isochrones created later
    in the work flow
    """

    geom_type = 'POLYGON'
    ospn = SpatialReference(2913)
    CreateFeatureclass(dirname(ISOCHRONES), basename(ISOCHRONES),
                       geom_type, spatial_reference=ospn)

    field_names = [
        ID_FIELD,  STOP_FIELD,  ROUTES_FIELD,
        ZONE_FIELD, YEAR_FIELD, DIST_FIELD]

    for f_name in field_names:
        if f_name in (ID_FIELD, YEAR_FIELD):
            f_type = 'LONG'
        elif f_name in (STOP_FIELD, ROUTES_FIELD, ZONE_FIELD):
            f_type = 'TEXT'
        elif f_name == DIST_FIELD:
            f_type = 'DOUBLE'

        AddField(ISOCHRONES, f_name, f_type)

    # drop Id field that is created by default
    DeleteField(ISOCHRONES, 'Id')
 def _get_extent(self, raster):
     import arcpy
     from arcpy import Raster, RasterToNumPyArray, SpatialReference
     try:
         transformations = arcpy.ListTransformations(
             raster.spatialReference, arcpy.SpatialReference(4326))
         if len(transformations) > 0:
             transformation = transformations[0]
         else:
             transformation = None
         extent = json.loads(
             raster.extent.projectAs(SpatialReference(4326),
                                     transformation).JSON)
         if extent["spatialReference"]["wkid"] is not None:
             return extent
         else:
             raise Exception(f"{extent} contains invalid spatial reference")
     except Exception as e:
         log.debug("Handled exception on inferring extent w/ arcpy engine")
         log.debug(e)
         return None
Exemple #6
0
def get_gauge(xpoint, ypoint, crs, comid=None, in_sr=None):
    '''gets the gauge according to x/y points or comid'''

    #get the spatial reference
    if in_sr is None:
        sr = SpatialReference(crs)
    else:
        sr = in_sr

    #read in the csv file with all of the gauges
    gauge_file = Shared.readCSVFile('C:\\GIS\\gagesiii_lat_lon.csv')
    headers = gauge_file[0]
    if "gage_no_1" in headers: idindex = headers.index("gage_no_1")
    if "gage_name" in headers: nmindex = headers.index("gage_name")
    if "COMID" in headers: comIDindex = headers.index("COMID")
    if "lat" in headers: latindex = headers.index("lat")
    if "lon" in headers: longindex = headers.index("lon")

    #remove header
    gauge_file.pop(0)

    #create all gauges and get the gauge closest to the provided x and y points
    gauge_data = []
    for station in gauge_file:
        gauge_data.append(
            gage(station[idindex], station[comIDindex], station[latindex],
                 station[longindex], sr, station[nmindex]))

    if comid is None:
        gauge_idx = np.array([
            np.abs((float(x.lat) - xpoint)) + np.abs((float(x.long) - ypoint))
            for x in gauge_data
        ]).argmin()
    else:
        gauge_idx = np.array(
            [np.abs(int(x.comid) - comid) for x in gauge_data]).argmin()

    return gauge_data[gauge_idx]
Exemple #7
0
        # the standard  spatial reference, show message
        # about this and pass to next feature
        if sr.name == sr_standard_file.name:
            print("This file: " + str(feature) +
                  ", already have the standard spatial reference")
            pass

        # If the name of spatial reference is different to
        # the standard  spatial reference
        # reproject file
        else:

            # Get spatial reference
            coor_system = str(sr_standard_file.name)
            coor_system = coor_system.replace("_", " ") + " (US Feet)"
            coor_system = SpatialReference(coor_system)

            # Output name
            feature_name = feature[:-4]
            out_name = "\\" + feature_name + "_projected"

            # Reproject file
            Project_management(feature, input_folder + out_name, coor_system)
            print("Projected: " + str(feature))

# If happen some error
except:
    # Show messages for error
    print GetMessages()

print "Completed script Project2"

if __name__ == "__main__":
    debug = False
    if debug:
        # Set local variables
        in_mosaic_dataset = r'C:\Users\geof7015\Documents\ArcGIS\Projects\Leveraging_LiDAR\scratch\SurfaceRasters\SurfaceMosaics.gdb\DTM'
        resampling_type = "BILINEAR"  # "NEAREST", "BILINEAR", "CUBIC", "MAJORITY"
        input_spatial_reference = ""
        out_spatial_reference_string = "WGS 1984"
        geographic_transform = "NAD_1983_To_WGS_1984_5"
        file_extension = "tif"
        out_directory = r''
        out_mosaic_dataset = r''
        # System Parameters
        out_spatial_reference = SpatialReference(out_spatial_reference_string)
    else:
        from arcpy import GetParameterAsText
        in_mosaic_dataset = GetParameterAsText(0)

        input_spatial_reference = arcpy.SpatialReference()
        input_spatial_reference.loadFromString(GetParameterAsText(1))

        out_spatial_reference = arcpy.SpatialReference()
        out_spatial_reference.loadFromString(GetParameterAsText(2))

        geographic_transform = GetParameterAsText(3)
        resampling_type = GetParameterAsText(4)
        file_extension = GetParameterAsText(5)
        out_directory = GetParameterAsText(6)
        out_mosaic_dataset = GetParameterAsText(7)
flLEPC = GetParameterAsText(3)
flCounty = GetParameterAsText(4)
strFilePath = GetParameterAsText(5)

# Convert values from text to float
floLatitude = float(strLatitude)
floLongitude = float(strLongitude)

# Make a Point Geometry object.
try:
    ptPointOfInterest = Point(X=floLongitude,
                              Y=floLatitude,
                              Z=None,
                              M=None,
                              ID=0)
    spatial_ref = SpatialReference(4269)
    ptGeometry = PointGeometry(ptPointOfInterest, spatial_ref)
except:
    strErrorMsg = "Error creating Point or PointGeometry objects."
    AddWarning(strErrorMsg)
    SetParameterAsText(6, strErrorMsg)
    sys.exit()

# Open Output File for use
try:
    fhand = open(strFilePath, 'w')
except:
    strErrorMsg = "File did not open"
    AddWarning(strErrorMsg)
    SetParameterAsText(6, strErrorMsg)
    sys.exit()
Exemple #10
0
# Defaults & static data

from arcpy import SpatialReference

defaults = {
    'api_request_time_interval' : 60000,
    'profile_chunk_size' : 1000
}

ref = 4326 # WGS-84
ref_arc = SpatialReference(ref)

endpoints = {
    'routing' : 'https://utility.arcgis.com/usrsvcs/appservices/{}/rest/services/World/Route/NAServer/Route_World/solve',
    'profile' : 'https://utility.arcgis.com/usrsvcs/appservices/{}/rest/services/Tools/Elevation/GPServer/Profile/submitJob',
    'summarize_elevation' : 'https://utility.arcgis.com/usrsvcs/appservices/{}/rest/services/Tools/Elevation/GPServer/SummarizeElevation/submitJob'
}

urls = {
    'token' : 'https://www.arcgis.com/sharing/rest/oauth2/token',
    'route' : 'https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve'
}

token_request_header = {
    'content-type': "application/x-www-form-urlencoded",
    'accept': "application/json",
    'cache-control': "no-cache"
}
Exemple #11
0
lsFileNamesTIF = []
lsFileNamesTFW = []
dictTFWCheck = {}
dictReportData = {}
setOfFileExtensions = None

#_____________________________________________________________________________________________________________________
# PROCESSING VARIABLES
# General
strConsolidatedImageFileFolderPath = None
strGeodatabaseWorkspacePath = None
strRasterCatalogName = "RCmanaged_{}".format(strDateTodayNoDashes)
strPSADefiningProjection = "Defining projection... {}"
strPSAReProjecting = "Re-Projecting... {}"
strPSAWorkspaceToRasterCatalog = "Loading workspace into raster catalog..."
strPSAListOfFailedReProjections = "The following list of lowercase filenames did not Re-Project\n{}"
strGeographicTransformationNAD83_WGS84 = "NAD_1983_To_WGS_1984_1"
strRasterManagementType = "MANAGED"
intDefineProjectionCode = 26985  # WKID 2248 is feet, WKID 26985 is meters
intProjectRasterCode = 3857  # WKID 3857 is web mercator
objSpatialReferenceProjectedRaster = SpatialReference(intProjectRasterCode)
# Input prompt messages
strPromptForConsolidatedImageFileFolderPath = "Paste the path to the folder containing the consolidated image files.\n>"
strPromptForGeodatabaseWorkspacePath = "Paste the path to the workspace (geodatabase).\n>"
# Error messages
strErrorMsgPathInvalid = "Path does not appear to exist. \n{}\n"
strErrorMsgWalkingDirectoryAndObjectCreationFail = "Error walking directory and creating Image object.\n{}"
# Collections
lsTifFilesInImagesFolder = []
lsUnsuccessfulImageReProjections = []