コード例 #1
0
    # Process: Con
    arcpy.gp.Con_sa(Slope_Clip, Input_true_constant__1, Slope_LT_MaxSlopeValue,
                    "", "\"VALUE\" <= %MaxSlopeValue%")

    # Process: Raster to Polygon
    arcpy.RasterToPolygon_conversion(Slope_LT_MaxSlopeValue, Slope_Polys,
                                     "SIMPLIFY", "VALUE")

    # Process: Dissolve Slope Polygons
    arcpy.Dissolve_management(Slope_Polys, Dissolved_Slope_Polygons, "", "",
                              "SINGLE_PART", "DISSOLVE_LINES")

    # Process: Create Spatial Reference
    arcpy.CreateSpatialReference_management(
        "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]];-20037700 -30241100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision",
        "", "", "", "", "", "0")

    # Process: Project Slope Polygons
    arcpy.Project_management(
        Dissolved_Slope_Polygons, Projected_Slope_Polygons,
        Output_Spatial_Reference, "",
        "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]"
    )

    # Process: Make Feature Layer (2)
    arcpy.MakeFeatureLayer_management(
        Projected_Slope_Polygons, Dissolved_Projected_Layer, "", "",
        "Shape Shape VISIBLE NONE;OBJECTID OBJECTID VISIBLE NONE")

    # Process: Add Centerpoint Spacing Field
# Create mask files from point shapefile
print("Creating mask files from point shapefile...")
maskStartTime = time.time()
# Create scratch folder
if os.path.exists(mask_scratch + "\\GEOG490_maskscratch"):
    print("*Deleting old GEOG490_maskscratch first...")
    arcpy.Delete_management(mask_scratch + "\\GEOG490_maskscratch")
arcpy.CreateFolder_management(mask_scratch, "GEOG490_maskscratch")
# Create scratch geodatabase
if os.path.exists(mask_scratch + "\\GEOG490_maskscratch.gdb"):
    print("*Deleting old GEOG490_maskscratch.gdb first...")
    arcpy.Delete_management(mask_scratch + "\\GEOG490_maskscratch.gdb")
arcpy.CreateFileGDB_management(mask_scratch, "GEOG490_maskscratch.gdb")

# Set raster as basis for coordinate system
sr = arcpy.CreateSpatialReference_management("", raster_location + raster_file)
# Process: Project
arcpy.Project_management(
    mask_location + mask_file,
    mask_scratch + "\\GEOG490_maskscratch.gdb\\" + mask_file[:-4] + "_proj",
    sr)
# Process: Buffer
arcpy.Buffer_analysis(
    mask_scratch + "\\GEOG490_maskscratch.gdb\\" + mask_file[:-4] + "_proj",
    mask_scratch + "\\GEOG490_maskscratch.gdb\\" + mask_file[:-4] + "_buffer",
    buffer_size, "FULL", "ROUND", "NONE", "", "PLANAR")
# Process: Feature Envelope To Polygon
arcpy.FeatureEnvelopeToPolygon_management(
    mask_scratch + "\\GEOG490_maskscratch.gdb\\" + mask_file[:-4] + "_buffer",
    mask_scratch + "\\GEOG490_maskscratch.gdb\\" + mask_file[:-4] +
    "_masktemp", "SINGLEPART")
コード例 #3
0
def main(*argv):
    """
        Main function for data discovery
    """
    try:
        # Read user input
        #
        servicelayer = argv[0]
        outputws = argv[1]
        outputgdb = argv[2]
        mdname = argv[3]
        polygonfeat = argv[4]
        cellsize = float(argv[5])
        clipping = argv[6]
        nodataVal = float(argv[7])
        userr = argv[8]

        #... read more as optional parameters

        # Check image service layer or URL
        if not arcpy.Exists(servicelayer):
            if servicelayer.startswith(
                    "http") and servicelayer.lower().find("imageserver") != -1:
                arcpy.AddMessage("Input is a service URL")
                serviceURL = servicelayer
            else:
                arcpy.AddError("Invalid Input.")
                return
        else:
            islayer = arcpy.mapping.Layer(servicelayer)
            # Check if the image service is from mosaic dataset
            if not (islayer.isServiceLayer and islayer.isRasterLayer):
                arcpy.AddError("Layer is not Image Service layer")
                return
            elif not islayer.supports("DEFINITIONQUERY"):
                arcpy.AddError(
                    "Image Service is not publish from Mosaic Dataset")
                return
            # Get service URL from the image service layer
            serviceURL = islayer.serviceProperties["URL"]

        # Get general service information
        inforeq = getISinfo(serviceURL)
        isprj = inforeq[0]
        pixtype = inforeq[1]
        defaultrr = inforeq[2]

        # Get spatial query request, item fields, values and spatial reference
        queryres = getQueryFields(serviceURL, polygonfeat)
        itemfields = queryres[0]
        itemfeatures = queryres[1]

        # Define output mosaic dataset path
        mdpath = os.path.join(outputgdb, mdname)

        # Check if there is items to download
        if len(itemfeatures) > 0:

            arcpy.AddMessage(
                "Found items to download, creating mosaic dataset...")
            mdprj = arcpy.CreateSpatialReference_management(isprj["wkid"])

            # Create output mosaic dataset and recover fields
            # Create File GDB for shipping md
            if not arcpy.Exists(outputgdb):
                arcpy.CreateFileGDB_management(os.path.dirname(outputgdb),
                                               os.path.basename(outputgdb))
            # Create output mosaic dataset
            arcpy.env.overwriteOutput = 1
            arcpy.CreateMosaicDataset_management(outputgdb, mdname, mdprj)

            # Recover fields from the image service
            missingfieldsName = recoverFields(itemfields, mdpath)
        else:
            arcpy.AddError("No raster can be downloaded")

        # Download raster one by one, and add raster one by one
        for itemfeature in itemfeatures:
            itematt = itemfeature["attributes"]
            itemgeo = itemfeature["geometry"]["rings"][0]
            itemoid = itematt["OBJECTID"]

            #Get clipping bounding box for each item
            bbox = getbbox(polygonfeat, itemgeo, mdprj)
            #Generate download image
            file_name = downloaditem(serviceURL, itemoid, defaultrr, bbox,
                                     cellsize, isprj, pixtype, userr, outputws)
            #Clip output image to polygon geometry if clipping is true
            if clipping:
                clipimage(file_name, polygonfeat, itemoid, nodataVal)

            # Add downloaded raster to output mosaic dataset
            addrasters(mdpath, outputws, itematt)

        arcpy.AddMessage("All done")

    except:
        arcpy.AddError("Clip and ship application failed")
コード例 #4
0
    # Path to feature dataset that contains SSURGO feature classes
    FDpath = os.path.join(FGDBpath,"FD_RTSD")

    # SSURGO layer Name
    soilFC = "MUPOLYGON"
    muLineFC = "MULINE"
    muPointFC = "MUPOINT"
    soilSaFC = "SAPOLYGON"
    featPointFC = "FEATPOINT"
    featLineFC = "FEATLINE"

    # Set environment variables
    env.workspace = FDpath

    # Parse Datum from MUPOLYGON; can only get datum from a GCS not a projected CS
    spatialRef = str(arcpy.CreateSpatialReference_management("#",soilFC,"#","#","#","#"))

    userDatum_Start = spatialRef.find("DATUM") + 7
    userDatum_Stop = spatialRef.find(",", userDatum_Start) - 1
    userDatum = spatialRef[userDatum_Start:userDatum_Stop]

    AddMsgAndPrint(" \tOutput Coordinate System: " + arcpy.Describe(soilFC).spatialReference.name,0)
    AddMsgAndPrint(" \tOutput Datum: " + userDatum,0)

    if userDatum == "D_North_American_1983":
        AddMsgAndPrint(" \tGeographic Transformation: WGS_1984_(ITRF00)_To_NAD_1983",0 )

    env.geographicTransformations = "WGS_1984_(ITRF00)_To_NAD_1983"  # WKID 108190
    env.outputCoordinateSystem = spatialRef

    arcpy.SetProgressorLabel("Gathering information about Soil Survey datasets...")
コード例 #5
0
"""
TableXY2Shape.py
A script that reads the 'latitude' and 'longitude' fields in
C:\Workspace\PNW\Edmonds\Geology\Edmonds.gdb\Geology\Boreholes,
updates the geometry to those values, and re-writes the
'Easting' and 'Northing' fields.
"""

import arcpy

#fc = r'C:\Documents and Settings\ethoms\My Documents\ArcGIS\Default.gdb\Export_Output'
fc = r'C:\Workspace\PNW\Edmonds\Geology\Edmonds.gdb\Geology\Boreholes'

WGS84 = arcpy.CreateSpatialReference_management(
    r'C:\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj'
)

rows = arcpy.UpdateCursor(fc, '', WGS84)
for row in rows:
    if row.Longitude:
        lon = row.Longitude
        lat = row.Latitude
        pt = arcpy.CreateObject('point')
        pt.X = lon
        pt.Y = lat
        row.Shape = pt
        rows.updateRow(row)
        print row.Shape.getPart().X, row.Shape.getPart().Y
        row.Easting = row.Shape.getPart().X
        row.Northing = row.Shape.getPart().Y
        rows.updateRow(row)
コード例 #6
0
# Import the required modules
#
import arcpy
import sys
import traceback

arcpy.env.workspace = "C:/Data/myData.gdb"
try:
    arcpy.CreateSpatialReference_management()
    #--------------------------
    # Your code goes here
    #
    # See the table below for examples
    #--------------------------
except arcpy.ExecuteError:
    # Get the tool error messages
    #
    msgs = arcpy.GetMessages(2)

    # Return tool error messages for use with a script tool
    #
    arcpy.AddError(msgs)

    # Print tool error messages for use in Python/PythonWin
    #
    print msgs

except:
    # Get the traceback object
    #
    tb = sys.exc_info()[2]