# Get SSURGO data
gmlFilenames = getMapunitFeaturesForBoundingBox(outdir, bbox, mapunitExtended=True, tileBbox=False)

# Convert from gml to shp and then rasterize
for gmlFilename in gmlFilenames:
    gmlFilepath = os.path.join(outdir, gmlFilename)
    layerName = os.path.splitext(gmlFilename)[0]
    shpFilename = convertGMLToShapefile(config, outdir, gmlFilepath, layerName, args.t_srs)

    # Truncate attributes to 10 characters because shapefiles rely on ancient technology
    attrList = [elem[:10] for elem in ssurgolib.attributequery.attributeListNumeric] 
    if soilRasterResolution == -1:
        # Use DEM raster resolution as soil property raster resolution
        sys.stderr.write("Using DEM resolution for soil property rasters ...\n")
        rasterizeSSURGOFeatures(config=config, outputDir=outdir, featureFilename=shpFilename, featureLayername=layerName, \
                                featureAttrList=attrList, \
                                getResolutionFromRasterFileNamed=demFilename)
    else:
        # Use user-specified soil raster resolution, but convert from meters into soil feature linear units
        sys.stderr.write("Using user-supplied resolution, %d meters x %d meters, for soil property rasters ...\n" % (soilRasterResolution, soilRasterResolution))
        rasterizeSSURGOFeatures(config=config, outputDir=outdir, featureFilename=shpFilename, featureLayername=layerName, \
                               featureAttrList=attrList, \
                               rasterResolutionX=soilRasterResolution, rasterResolutionY=soilRasterResolution)                     

    #solimCommand = "%s %s MUKEY %s %s avgSand,avgSilt,avgClay,avgKsat,avgPorosity" % \
    #    (solimCmdPath, shpFilename, demFilename, outdir)
    #print solimCommand
    #returnCode = os.system(solimCommand)
    returnCode = inferSoilPropertiesForSSURGOAndTerrainData(config, outdir, shpFilename, demFilename)
    assert(returnCode == 0)
    
for gmlFilename in gmlFilenames:
    gmlFilepath = os.path.join(outdir, gmlFilename)
    layerName = os.path.splitext(gmlFilename)[0]
    shpFilename = convertGMLToShapefile(config, outdir, gmlFilepath, layerName,
                                        args.t_srs)

    # Truncate attributes to 10 characters because shapefiles rely on ancient technology
    attrList = [
        elem[:10] for elem in ssurgolib.attributequery.attributeListNumeric
    ]
    if soilRasterResolution == -1:
        # Use DEM raster resolution as soil property raster resolution
        sys.stderr.write(
            "Using DEM resolution for soil property rasters ...\n")
        rasterizeSSURGOFeatures(config=config, outputDir=outdir, featureFilename=shpFilename, featureLayername=layerName, \
                                featureAttrList=attrList, \
                                getResolutionFromRasterFileNamed=demFilename)
    else:
        # Use user-specified soil raster resolution, but convert from meters into soil feature linear units
        sys.stderr.write(
            "Using user-supplied resolution, %d meters x %d meters, for soil property rasters ...\n"
            % (soilRasterResolution, soilRasterResolution))
        rasterizeSSURGOFeatures(config=config, outputDir=outdir, featureFilename=shpFilename, featureLayername=layerName, \
                               featureAttrList=attrList, \
                               rasterResolutionX=soilRasterResolution, rasterResolutionY=soilRasterResolution)

    #solimCommand = "%s %s MUKEY %s %s avgSand,avgSilt,avgClay,avgKsat,avgPorosity" % \
    #    (solimCmdPath, shpFilename, demFilename, outdir)
    #print solimCommand
    #returnCode = os.system(solimCommand)
    returnCode = inferSoilPropertiesForSSURGOAndTerrainData(
if not os.path.isdir(outdir):
    raise IOError(errno.ENOTDIR, "Output directory %s is not a directory" % (outdir,))
if not os.access(outdir, os.W_OK):
    raise IOError(errno.EACCES, "Not allowed to write to output directory %s" %
                  outdir)
outdir = os.path.abspath(outdir)
os.chdir(outdir)

soilRasterResolutionX = args.soilrasterresolution[0]
soilRasterResolutionY = args.soilrasterresolution[1]

# Get bounding box
bbox = getBoundingBoxForShapefile(shapefile)
print "Bounding box: (%f, %f) (%f, %f)" % (bbox['minX'], bbox['minY'], bbox['maxX'], bbox['maxY'])

# Get SSURGO data
gmlFilenames = getMapunitFeaturesForBoundingBox(outdir, bbox, mapunitExtended=True, tileBbox=False)
    
# Convert from gml to shp and then rasterize
for gmlFilename in gmlFilenames:
    gmlFilepath = os.path.join(outdir, gmlFilename)
    layerName = os.path.splitext(gmlFilename)[0]
    shpFilename = convertGMLToShapefile(config, outdir, gmlFilepath, layerName, args.t_srs)

    # Truncate attributes to 10 characters because shapefiles rely on ancient technology
    attrList = [elem[:10] for elem in ssurgolib.attributequery.attributeListNumeric] 
    rasterizeSSURGOFeatures(config=config, outputDir=outdir, featureFilename=shpFilename, featureLayername=layerName, \
                           featureAttrList=attrList, \
                           rasterResolutionX=soilRasterResolutionX, rasterResolutionY=soilRasterResolutionY)                     

예제 #4
0
os.chdir(outdir)

soilRasterResolutionX = args.soilrasterresolution[0]
soilRasterResolutionY = args.soilrasterresolution[1]

# Get bounding box
bbox = getBoundingBoxForShapefile(shapefile)
print("Bounding box: (%f, %f) (%f, %f)" %
      (bbox['minX'], bbox['minY'], bbox['maxX'], bbox['maxY']))

# Get SSURGO data
gmlFilenames = getMapunitFeaturesForBoundingBox(outdir,
                                                bbox,
                                                mapunitExtended=True,
                                                tileBbox=False)

# Convert from gml to shp and then rasterize
for gmlFilename in gmlFilenames:
    gmlFilepath = os.path.join(outdir, gmlFilename)
    layerName = os.path.splitext(gmlFilename)[0]
    shpFilename = convertGMLToShapefile(config, outdir, gmlFilepath, layerName,
                                        args.t_srs)

    # Truncate attributes to 10 characters because shapefiles rely on ancient technology
    attrList = [
        elem[:10] for elem in ssurgolib.attributequery.attributeListNumeric
    ]
    rasterizeSSURGOFeatures(config=config, outputDir=outdir, featureFilename=shpFilename, featureLayername=layerName, \
                           featureAttrList=attrList, \
                           rasterResolutionX=soilRasterResolutionX, rasterResolutionY=soilRasterResolutionY)