Exemplo n.º 1
0
def create_mosaics():

    print "Creating geodatabase for loss and fire mosaics in Amazonia..."
    out_coor_system = arcpy.Describe(loss_tile).spatialReference
    print "  Creating gdb..."
    arcpy.CreateFileGDB_management(dir, gdb)

    print "  Creating Hansen loss mosaic..."
    arcpy.CreateMosaicDataset_management("{}.gdb".format(gdb_path),
                                         Hansen_mosaic,
                                         out_coor_system,
                                         num_bands="1",
                                         pixel_type="8_BIT_UNSIGNED")
    print "  Adding Hansen loss tiles to mosaic..."
    arcpy.AddRastersToMosaicDataset_management(
        "{0}.gdb/{1}".format(gdb_path, Hansen_mosaic),
        raster_type="Raster Dataset",
        input_path=Hansen_loss_tile_path)

    # I haven't actually tested this code out. It's based on the Python snippet from manually clipping, so it might
    # not work as I've modified it here. At least, the rectangle arguments need to change.
    print "  Clipping Hansen loss to Brazil boundary..."
    arcpy.Clip_management(
        in_raster="{0}.gdb/{1}".format(gdb_path, Hansen_mosaic),
        rectangle=
        "-73.9783164486978 -18.0406669808439 -43.9135843925793 5.27136996674568",
        out_raster=legal_Amazon_loss_dir,
        in_template_dataset="prodes_full_extent_reproj",
        nodata_value="256",
        clipping_geometry="ClippingGeometry",
        maintain_clipping_extent="NO_MAINTAIN_EXTENT")
def extract_loss(scratch, lossyearmosaic, country_shapefile_int, iso, scratch_gdb):
    arcpy.CheckOutExtension("Spatial")
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = scratch_gdb
    arcpy.env.scratchWorkspace = scratch

    mosaic_name = iso + "_extract"
    sr = 4326
    iso_loss_mosaic = arcpy.CreateMosaicDataset_management(scratch_gdb, mosaic_name, sr)

    fields = ['ISO', 'SHAPE@']
    shapecount = 0
    with arcpy.da.SearchCursor(country_shapefile_int, fields) as cursor:
        for row in cursor:
            shapecount += 1
            iso_row = row[0]
            geometry = row[1]
            if iso_row == iso:
                country_loss_30tcd = arcpy.sa.ExtractByMask(lossyearmosaic, geometry)
                extracted_folder = os.path.join(scratch, "extracted_tifs")
                if not os.path.exists(extracted_folder):
                    os.mkdir(extracted_folder)
                extracted_tif = os.path.join(extracted_folder, "{0}_{1}.tif".format(iso, shapecount))
                country_loss_30tcd.save(extracted_tif)

                extracted_tif_nd = extracted_tif.replace(".tif", "_nd.tif")
                cmd = ["gdal_translate", "-a_nodata", "0", extracted_tif, extracted_tif_nd]
                subprocess.check_call(cmd)

    # arc having trouble deleting pre-nodata files, so just adding nd to mosaic
    nd_tifs = glob.glob(os.path.join(extracted_folder, "{}*nd*".format(iso)))
    for tif in nd_tifs:
        arcpy.AddRastersToMosaicDataset_management(iso_loss_mosaic, "Raster Dataset", tif)

    return iso_loss_mosaic
Exemplo n.º 3
0
def main():

    # Parse commandline arguments
    parser = argparse.ArgumentParser(description='make mosaics')
    parser.add_argument(
        '--geodatabase',
        '-g',
        required=True,
        help='path to geodatabase where mosaics will be created')

    args = parser.parse_args()
    for mosaic in ['tcd', 'area', 'loss', 'biomass']:
        print "building mosaic for {}".format(mosaic)
        path_dict = {
            'tcd': r'S:\treecoverdensity_2000',
            'area': r'S:\area_tiles',
            'loss': r'S:\lossdata_2001_2014',
            'biomass': r'S:\biomass'
        }
        out_cs = arcpy.SpatialReference(4326)
        arcpy.CreateMosaicDataset_management(args.geodatabase, mosaic, out_cs)

        # add rasters
        mosaic_name = os.path.join(args.geodatabase, mosaic)
        rastype = "Raster Dataset"
        path_to_files = path_dict[mosaic]

        arcpy.AddRastersToMosaicDataset_management(mosaic_name, rastype,
                                                   path_to_files)
Exemplo n.º 4
0
def make_mosaic_from_tiles(dem_tiles_folder,
                           mosaic_name,
                           geodatabase,
                           coordinate_system,
                           make_gdb=True,
                           export_to_raster=False):

    if not arcpy.Exists(geodatabase) and make_gdb is True:
        folder, name = os.path.split(geodatabase)
        arcpy.CreateFileGDB_management(folder, name)

    print("Making Mosaic Dataset")
    arcpy.CreateMosaicDataset_management(geodatabase,
                                         mosaic_name,
                                         coordinate_system,
                                         num_bands=1)
    mosaic_dataset = os.path.join(geodatabase, mosaic_name)

    print("Adding Tiles to Dataset")
    arcpy.AddRastersToMosaicDataset_management(
        mosaic_dataset,
        "Raster Dataset",
        dem_tiles_folder,
        update_overviews="UPDATE_OVERVIEWS")

    if export_to_raster:
        arcpy.MosaicToNewRaster_management(mosaic_dataset,
                                           geodatabase,
                                           "{}_export".format(mosaic_name),
                                           pixel_type="32_BIT_FLOAT",
                                           number_of_bands=1)
Exemplo n.º 5
0
def createMosaicDataset(gdbPath, mdName, prjFile):
    """
    1.创建镶嵌数据集
    3.开启自动跟踪功能    会自动添加四个属性字段
    """
    gdbname = gdbPath
    mdname = mdName
    prjfile = prjFile
    noband = "1"
    pixtype = "32_BIT_FLOAT"

    # 1.创建镶嵌数据集
    mdpath = gdbPath + "/" + mdName
    if not arcpy.Exists(mdpath):
        arcpy.CreateMosaicDataset_management(gdbname, mdname, prjfile, noband, pixtype)

    # 2.并添加四个属性字段
    # if arcpy.Exists(mdpath):
    #     arcpy.AddField_management(mdpath, 'createpreson', 'TEXT', 18, 11)
    #     arcpy.AddField_management(mdpath, 'createtime', 'DATE')
    #     arcpy.AddField_management(mdpath, 'updateepreson', 'TEXT', 18, 11)
    #     arcpy.AddField_management(mdpath, 'updatetime', 'DATE')

    # 3.开启自动跟踪功能
    desc = arcpy.Describe(mdpath)
    if not desc.editorTrackingEnabled:
        arcpy.EnableEditorTracking_management(mdpath, "createperson", "createtime", "updateperson", "updatetime",
                                              "ADD_FIELDS", "UTC")
Exemplo n.º 6
0
 def mosaic_ndwi(self, gcs):
     self.gcs = gcs
     for ext in self.file_extension:
         filters = ext
         filters_new = "*" + filters
         # Creates a file geodatabase
         geodatabase_file_name = 'NDWI_GDB' + '_' + filters[:-4] + '.gdb'
         print(geodatabase_file_name)
         #Creates a raster dataset with .tif extension
         mosaiced_raster_name = 'NDWI_Mosaiced' + '_' + filters[:-4] + '.tif'
         print(mosaiced_raster_name)
         # 1) Creates a file geodatabase in a folder
         print('Creating Geodatabase file: {} of {} ... ^_^'.format(
             ext, self.file_extension))
         output_dir = os.path.join(self.main_dir, self.subfolder_1,
                                   self.subfolder_3)
         # output_dir_serach = os.path.split(output_dir)[0]
         print('Output_directory {}:'.format(output_dir))
         arcpy.CreateFileGDB_management(
             output_dir, geodatabase_file_name)  # Creates gdb file
         print('Done!^_^')
         # 2) Creates an empty mosaic dataset in a file geodatabase
         in_workspace = os.path.join(
             output_dir, geodatabase_file_name)  # Path to the geodatabase
         in_mosaicdataset_name = 'NDWI_RasterDataset' + '_' + filters[:-4]
         NumberOfBand = "1"
         PixelType = "32_BIT_FLOAT"  # Pixel type can be changed
         product_definition = "NONE"
         Wavelength = ""
         print('Creating an empty mosaic dataset: {} of {} ... ^_^'.format(
             ext, self.file_extension))
         arcpy.CreateMosaicDataset_management(in_workspace,
                                              in_mosaicdataset_name,
                                              self.gcs, NumberOfBand,
                                              PixelType, product_definition,
                                              Wavelength)
         print('Done!^_^')
         # 3) Add raster dataset to a mosaic dataset from many sources, including a file, folder, raster catalog, table, or web service.
         in_mosaic_dataset = os.path.join(in_workspace,
                                          in_mosaicdataset_name)
         print(
             'Adding rasters to an empty mosaic dataset: {} of {} ... ^_^'.
             format(ext, self.file_extension))
         arcpy.AddRastersToMosaicDataset_management(in_mosaic_dataset, "Raster Dataset", output_dir, \
                                                 "UPDATE_CELL_SIZES","UPDATE_BOUNDARY","NO_OVERVIEWS","2","#","#",'#', filters_new, "SUBFOLDERS",\
                                                 "EXCLUDE_DUPLICATES","NO_PYRAMIDS","NO_STATISTICS","NO_THUMBNAILS","#","NO_FORCE_SPATIAL_REFERENCE")
         print('Done! ^_^')
         # 4) Creates a folder to copy NDWI mosaiced dataset
         in_raster = os.path.join(in_workspace, in_mosaicdataset_name)
         ndwi = os.path.join(output_dir, 'NDWI_Mosaic' + '_' + filters[:-4])
         if not os.path.exists(ndwi):
             os.makedirs(ndwi)
         print('Copying raster: {} of {} ... ^_^'.format(
             ext, self.file_extension))
         out_raster = os.path.join(ndwi, mosaiced_raster_name)
         arcpy.CopyRaster_management(in_raster, out_raster, "#", "0", "0",
                                     "NONE", "NONE", "32_BIT_FLOAT", "NONE",
                                     "NONE")
         print('Done! ^_^ ^_^ ^_^')
Exemplo n.º 7
0
def create_mosaic(country_loss_30tcd, scratch_gdb):
    out_cs = arcpy.SpatialReference(4326)
    mosaic_name = "mosaic_country_loss_30tcd"
    mosaic_path = os.path.join(scratch_gdb, mosaic_name)
    arcpy.CreateMosaicDataset_management(scratch_gdb, mosaic_name, out_cs)
    arcpy.AddRastersToMosaicDataset_management(mosaic_path, "Raster Dataset",
                                               country_loss_30tcd)
    return os.path.join(scratch_gdb, mosaic_name)
Exemplo n.º 8
0
    def __init__(self, output_basepath, dataset_name, coordinate_system,
                 options):
        ArcTable.__init__(self, output_basepath, dataset_name, options)

        if not arcpy.Exists(self.fullpath):
            arcpy.CreateMosaicDataset_management(output_basepath, dataset_name,
                                                 coordinate_system,
                                                 options.get('num_bands'),
                                                 options.get('pixel_type'))
Exemplo n.º 9
0
    def mosaic_dem_cal_slp(self, gdb_name, folder2save_mosaic_ras, mosaiced_dem_ras_name,
                           projection, folder2save_slp_ras, slp_ras_name, z_factor):
        self.gdb_name = gdb_name
        self.folder2save_mosaic_ras = folder2save_mosaic_ras
        self.mosaiced_dem_ras_name = mosaiced_dem_ras_name
        self.projection = projection
        self.folder2save_slp_ras = folder2save_slp_ras
        self.slp_ras_name = slp_ras_name
        self.z_factor = z_factor
        file_path = os.path.join(self.main_dir, self.subfolder_1)
        gdb_file_path = os.path.join(self.main_dir, self.subfolder_1, self.subfolder_3)
        print('Creating geodatabase file... ^__^')
        arcpy.CreateFileGDB_management(gdb_file_path, self.gdb_name)
        print('Creating an empty raster dataset inside geodatabse... ^__^')
        mosaic_dataset_name = 'My_RasterDataset'
        mosaicgdb = os.path.join(gdb_file_path, self.gdb_name)
        print("mosaicgdb", mosaicgdb)
        NumberOfBand = "1"
        PixelType = "16_BIT_SIGNED" # Pixel type can be changed
        ProductDefinition = "NONE"
        Wavelength = ""
        arcpy.CreateMosaicDataset_management(mosaicgdb, mosaic_dataset_name, self.projection, NumberOfBand, PixelType, ProductDefinition, Wavelength)
        print('Adding DEM rasters into an empty raster dataset... ^__^')
        path_and_nameof_mosaic_dataset = os.path.join(mosaicgdb, mosaic_dataset_name)
        arcpy.AddRastersToMosaicDataset_management(path_and_nameof_mosaic_dataset, "Raster Dataset",
                                                file_path, "UPDATE_CELL_SIZES","UPDATE_BOUNDARY","NO_OVERVIEWS","2","#","#",
                                                self.projection, '*'+self.file_extension, "SUBFOLDERS","EXCLUDE_DUPLICATES","NO_PYRAMIDS","NO_STATISTICS",
                                                "NO_THUMBNAILS","#","FORCE_SPATIAL_REFERENCE")
        in_raster = os.path.join(mosaicgdb, mosaic_dataset_name)
        create_folder = os.path.join(self.main_dir, self.subfolder_1, self.subfolder_3, self.folder2save_mosaic_ras)
        if not os.path.exists(create_folder):
            os.makedirs(create_folder)
        out_raster = os.path.join(create_folder, self.mosaiced_dem_ras_name)
        arcpy.CopyRaster_management(in_raster, out_raster, "#","#","#","NONE","NONE","16_BIT_UNSIGNED","NONE","NONE")

        def slope_cal():
            print('Reading DEM! ^_^')
            read_dem = arcpy.Raster(out_raster)
            print('Caculating slope... ^__^')
            arcpy.CheckOutExtension("spatial")
            slope_raster = Slope(read_dem, "DEGREE", self.z_factor)
            arcpy.CheckInExtension("spatial")
            slope_cal_path = os.path.join(self.main_dir, self.subfolder_1, self.subfolder_3, self.folder2save_slp_ras)
            if not os.path.exists(slope_cal_path):
                os.makedirs(slope_cal_path)
            slope_file = os.path.join(slope_cal_path, self.slp_ras_name)
            print('Writing slope raster... ^__^')
            slope_raster.save(slope_file)
            print('Done! ^__^')
            print('Resampling Slope raster...')
            arcpy.CheckOutExtension("spatial")
            in_ras_resample = arcpy.Raster(slope_file)
            resampled_slope_file = os.path.join(slope_cal_path, 'Resam_' + self.slp_ras_name)
            arcpy.Resample_management(in_ras_resample, resampled_slope_file, "8.9831528e-05", "BILINEAR")
            arcpy.CheckInExtension("spatial")
            print('Done! ^__^')
        slope_cal()
Exemplo n.º 10
0
 def create_empty_mosaic_dataset(in_workspace, in_mosaicdataset_name, gcs):
     """Creates an empty mosaic dataset"""
     NumberOfBand = "1"
     PixelType = "32_BIT_FLOAT"  # Pixel type can be changed
     product_definition = "NONE"
     Wavelength = ""
     md = arcpy.CreateMosaicDataset_management(in_workspace,
                                               in_mosaicdataset_name, gcs,
                                               NumberOfBand, PixelType,
                                               product_definition,
                                               Wavelength)
     return md
Exemplo n.º 11
0
 def empty_mosaic_dataset(self, in_workspace, in_mosaicdataset_name):
     """Creates an empty mosaic dataset (emd)"""
     self.in_workspace = in_workspace
     self.in_mosaicdataset_name = in_mosaicdataset_name
     NumberOfBand = "1"
     PixelType = "32_BIT_FLOAT"  # Pixel type can be changed
     product_definition = "NONE"
     Wavelength = ""
     md = arcpy.CreateMosaicDataset_management(
         self.in_workspace, self.in_mosaicdataset_name, self.projection,
         NumberOfBand, PixelType, product_definition, Wavelength)
     return md
Exemplo n.º 12
0
 def CreateMosaicDataset(self):
     arcpy.CreateMosaicDataset_management(workspace,
                                          mosaic_name,
                                          coordinate_sys,
                                          num_bands="",
                                          pixel_type="",
                                          product_definition="NONE",
                                          product_band_definitions="")
     arcpy.AddRastersToMosaicDataset_management(
         mosaic_dataset, "Raster Dataset", path_to_files,
         "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY", "NO_OVERVIEWS", "", "0",
         "1500", imagery_spatial_ref, "#", "SUBFOLDERS", "ALLOW_DUPLICATES",
         "NO_PYRAMIDS", "NO_STATISTICS", "NO_THUMBNAILS", "#",
         "NO_FORCE_SPATIAL_REFERENCE")
Exemplo n.º 13
0
 def createMD(self):
     self.log("Creating source mosaic datasets:", self.const_general_text)
     try:
         mdPath = os.path.join(self.m_base.m_geoPath, self.m_base.m_mdName)
         if not arcpy.Exists(mdPath):
             self.log("\t" + self.m_base.m_mdName, self.const_general_text)
             arcpy.CreateMosaicDataset_management(
                 self.m_base.m_geoPath, self.m_base.m_mdName, self.srs,
                 self.num_bands, self.pixel_type, self.product_definition,
                 self.product_band_definitions)
     except:
         self.log("Failed!", self.const_critical_text)
         self.log(arcpy.GetMessages(), self.const_critical_text)
         return False
     return True
Exemplo n.º 14
0
def createMosaicDataset(gdb_path, md_name, spatial_reference):
    a = datetime.now()

    md_path = os.path.join(gdb_path, md_name)
    deleteFileIfExists(md_path, useArcpy=True)
    # Create a MD in same SR as file
    arcpy.CreateMosaicDataset_management(in_workspace=gdb_path,
                                         in_mosaicdataset_name=md_name,
                                         coordinate_system=spatial_reference,
                                         num_bands="1",
                                         pixel_type="32_BIT_FLOAT",
                                         product_definition="NONE",
                                         product_band_definitions="#")

    doTime(a, "\tCreated MD {}".format(md_path))

    return md_path
Exemplo n.º 15
0
    def create_mosaic_dataset(self):
        if not arcpy.Exists(self.output_gdb):
            arcpy.CreateFileGDB_management(os.path.dirnam(output_gdb),
                                           os.path.basename(output_gdb))

        if not arcpy.Exists(join(self.output_gdb, self.output_mosaic)):
            arcpy.CreateMosaicDataset_management(self.output_gdb,
                                                 self.output_mosaic,
                                                 self.mosaic_spatial_ref,
                                                 num_bands=self.numBands,
                                                 pixel_type="",
                                                 product_definition="NONE",
                                                 product_band_definitions="")

        arcpy.AddRastersToMosaicDataset_management(
            join(self.output_gdb, self.output_mosaic), "Raster Dataset",
            self.composite_path, "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY",
            "UPDATE_OVERVIEWS", "", "0", "1500", self.imagery_spatial_ref, "#",
            "SUBFOLDERS", "ALLOW_DUPLICATES", "NO_PYRAMIDS", "NO_STATISTICS",
            "NO_THUMBNAILS", "#", "NO_FORCE_SPATIAL_REFERENCE")
Exemplo n.º 16
0
def mosaicCreator(_mosaicPath, _simulationSteps):
    try:
        arcpy.CreateMosaicDataset_management(
            _mosaicPath, "Mosaic",
            "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]]",
            None, None, "NONE", None)

    except ExceptionI:
        arcpy.AddMessage("Exception")

    arcpy.AddMessage("Before Loop")
    rasters = ''
    for i in range(0, int(_simulationSteps), 50):
        file1 = _mosaicPath
        filePath = os.path.join(file1, "Frame" + str(i))
        rasters = rasters + ';' + filePath
        arcpy.AddMessage(filePath)

    arcpy.AddMessage("rasters:" + rasters)
    arcpy.management.AddRastersToMosaicDataset(
        os.path.join(_mosaicPath, 'Mosaic'), "Raster Dataset", rasters,
        "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY", "NO_OVERVIEWS", None, 0, 1500,
        None, None, "SUBFOLDERS", "ALLOW_DUPLICATES", "NO_PYRAMIDS",
        "CALCULATE_STATISTICS", "NO_THUMBNAILS", None,
        "NO_FORCE_SPATIAL_REFERENCE", "ESTIMATE_STATISTICS", None)

    # Set local variables
    inFeatures = os.path.join(_mosaicPath, 'Mosaic')
    fieldName1 = "Time_Stamp"
    fieldPrecision = 9
    fieldAlias = "time"

    # Execute AddField twice for two new fields
    arcpy.AddField_management(inFeatures,
                              fieldName1,
                              "LONG",
                              fieldPrecision,
                              field_alias=fieldAlias,
                              field_is_nullable="NULLABLE")
    arcpy.CalculateField_management(inFeatures, fieldName1, "!OBJECTID!")
    arcpy.AddMessage("After Loop")
Exemplo n.º 17
0
out_folder_path = path + r"\fileGDB"
out_name = "fGDB.gdb"
arcpy.CreateFileGDB_management(out_folder_path, out_name)
print "14"
print "Creating mosaic.."

# create empty mosaic dataset in fGDB.gdb
gdbname = path + r"\fileGDB\fGDB.gdb"
mdname = "mosaicds"
coordinate = "NAD 1983 StatePlane Florida East FIPS 0901 (US Feet)"
noband = "3"
pixtype = "8_BIT_UNSIGNED"
pdef = "NONE"
wavelength = ""

arcpy.CreateMosaicDataset_management(gdbname, mdname, coordinate, noband,
                                     pixtype, pdef, wavelength)
print "15"

# Add rasters to mosaic dataset
arcpy.env.workspace = sid_loc

arcpy.env.parallelProcessingFactor = "200%"  ######## DP increase

print "Adding rasters.."

mdname = gdbname + "/" + mdname
rastype = "Raster Dataset"
input_rasters = ";".join(name)
updatecs = "UPDATE_CELL_SIZES"
updatebnd = "UPDATE_BOUNDARY"
prj = arcpy.SpatialReference(102100)

#Add pdate Field to feature class so I can create space-time-ripple
arcpy.management.AddField(fc, "pdate", "DATE", None, None, None, "pdate",
                          "NULLABLE", "NON_REQUIRED", None)
arcpy.management.CalculateField(
    fc, "pdate", "datetime.datetime.strptime(!GAME_DATE!, '%m/%d/%Y')",
    "PYTHON", None)

#Get unique game dates
values = [row[0] for row in arcpy.da.SearchCursor(fc, "pdate")]
unique_game_dates = list(set(values))
print(unique_game_dates)

#create mosaic dataset for 2D space-time analysis
arcpy.CreateMosaicDataset_management(cum_md_gdb, cum_md_name, prj)
arcpy.AddField_management(out_md, "GAME_DATE", "DATE", None, None, None,
                          "pdate", "NULLABLE", "NON_REQUIRED", None)

#For every game, create feature classes that look at that game and all previous games
for date in unique_game_dates:
    print("selecting")
    out_fc_name = 'game_' + str(date.year) + '_' + str(date.month) + '_' + str(
        date.day)
    out_raster_name = out_fc_name + '_raster'
    out_hexbin_name = out_fc_name + '_hexbin'
    out_fc = os.path.join(cum_point_gdb, out_fc_name)
    out_hex_fc = os.path.join(cum_hex_gdb, out_hexbin_name)
    out_raster = os.path.join(cum_raster_gdb, out_raster_name)
    if arcpy.Exists(out_fc) == False:
        wc = "pdate <= date '%s'" % (date)  #
Exemplo n.º 19
0
    move(z, ".\processed_data")

unzipped = glob("DTM*") + glob("DSM*") + glob("intensity*")
for tiles in unzipped:
    move(tiles, ".\mosaic_data_source")

# create names for the new mosaic datasets
DTM = countyName + "_DTM"
DSM = countyName + "_DSM"
intensity = countyName + "_intensity"

# create a geodatabase to store the mosaic datasets
arcpy.CreateFileGDB_management(os.getcwd(), countyName)

# create a mosaic dataset for the DTM and the DSM
arcpy.CreateMosaicDataset_management(os.path.abspath(countyName + ".gdb"), DTM,
                                     projfile)
arcpy.CreateMosaicDataset_management(os.path.abspath(countyName + ".gdb"), DSM,
                                     projfile)
arcpy.CreateMosaicDataset_management(os.path.abspath(countyName + ".gdb"),
                                     intensity, projfile)

DTMList = []
DSMList = []
intensityList = []

# make 3 lists containing the path of all DTM tif files, all DSM tif files, and all intensity raster files
os.chdir(mosaicDataSource)
for tif in glob("DTM_" + countyName + "*.tif"):
    #print ("Found DTM: "+tif)
    DTMList.append(os.path.abspath(tif))
for tif in glob("DSM_" + countyName + "*.tif"):
Exemplo n.º 20
0
#arcpy.env.overwriteOutput = True
# create file GDB

if not os.path.exists(
        os.path.join("C:\\", "Imagenes_Satelitales_ANM", "area_" + area,
                     "Mosaico", year, month, gdb_name + '.gdb')):
    arcpy.CreateFileGDB_management(gdb_location, gdb_name, "CURRENT")
    print "GDB" + " del area " + area + " y" + " fecha " + year + month + " ha sido creada"
else:
    print("GDB ya existe, verifique")
    print(" el script no puede continuar y se cerrara")
    sys.exit()

# Process: Create Mosaic Dataset
arcpy.CreateMosaicDataset_management(m_location, mosaic_name, coords, "4",
                                     "16_BIT_UNSIGNED", "NONE", "")

print "Dataset de Mosaico ha sido creado"

# Process: Create Statistics

rasters = arcpy.ListRasters(Input_Data_Filter)

for raster in rasters:

    arcpy.BuildPyramidsandStatistics_management(
        Input_Rasters_Data_Folder, "INCLUDE_SUBDIRECTORIES", "BUILD_PYRAMIDS",
        "CALCULATE_STATISTICS", "NONE", "", "NONE", "1", "1", "", "-1", "NONE",
        "NEAREST", "DEFAULT", "75", "OVERWRITE")

    print "se han caculado estadisticas a la imagen" + (raster)
Exemplo n.º 21
0
    arcpy.Warp_management(temp_file_and_path, source_pnt, target_pnt,
                          output_file_and_path, "POLYORDER1", "BILINEAR")
    #Deleting the unreference image
    arcpy.Delete_management(temp_file_and_path)
    print(output_file_and_path)

#Composite bands
arcpy.env.workspace = output_image_path
rasters = arcpy.ListRasters(galaxy + "*", "TIF")
arcpy.CompositeBands_management(rasters, composite_path_and_name)

#Create the mosaic and add images to it
coordinate_sys = "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"
imagery_spatial_ref = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision"
mosaic_gdb = r"C:\PROJECTS\R&D\ASTROARC\SINGS\Spitzer.gdb"
mosaic_name = "SINGS"
mosaic_dataset = os.path.join(mosaic_gdb, mosaic_name)
arcpy.CreateMosaicDataset_management(mosaic_gdb,
                                     mosaic_name,
                                     coordinate_sys,
                                     num_bands="",
                                     pixel_type="",
                                     product_definition="NONE",
                                     product_band_definitions="")
arcpy.AddRastersToMosaicDataset_management(
    mosaic_dataset, "Raster Dataset", composite_image_path,
    "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY", "NO_OVERVIEWS", "", "0", "1500",
    imagery_spatial_ref, "#", "SUBFOLDERS", "ALLOW_DUPLICATES", "NO_PYRAMIDS",
    "NO_STATISTICS", "NO_THUMBNAILS", "#", "NO_FORCE_SPATIAL_REFERENCE")

print("Done.")
# variables
cities = ["Carpinteria", "SantaBarbara", "Goleta"]
heights = range(1,11)                                   #sets the heights variable, from 1 meters to 10 meters
years_beg = [2010 + 10 * h for h in heights]            
years_end = [2020 + 10 * h for h in heights]            #sets the time periods that the rasters represent, this is a very arbitrary estimate: 1 meter per decade

# iterate over cities
for city in cities:
    dem = "dem_" + city + ".tif"                        #sets dem variable to select the right city

    # create slr_city mosaic to associate time with rasters
    slr_city = "slr_" + city
    gdb_slr_city = gdb + "/" + slr_city                                 #sets variables to use in the raster mosaic
    print("Creating slr_city mosaic: " + slr_city)
    arcpy.CreateMosaicDataset_management(gdb, slr_city, sr, 1, "1_BIT") #adds a mosaic of rasters to the sb_slr_geodatabase
    arcpy.AddField_management(gdb_slr_city, "YearBeg", "SHORT")         
    arcpy.AddField_management(gdb_slr_city, "YearEnd", "SHORT")         #adds the time element to the new rasters in the mosaic

    # iterate over slr heights
    for height in heights:
        slr_city_height = ws + "/slr_" + city + "_" + str(height) + "m.tif"     #defines the workplace and name for each raster
    
        # calculate slr_city_height raster
        if not arcpy.Exists(slr_city_height):                                   #checks to see if the raster exists
            print("  Creating slr_city_height raster: " + os.path.basename(slr_city_height))
            r = Con(Raster(dem) <= height, 1)                                                           #creates a new raster with the specified height
            r.save(slr_city_height)                                                                     #saves the raster
        arcpy.AddRastersToMosaicDataset_management(gdb_slr_city, "Raster Dataset", slr_city_height)     #adds the newly created raster to the mosaic
        
    # update YearBeg & YearEnd in slr_city mosaic
Exemplo n.º 23
0
)  # clipping feature: "D:/LittleMissouri_River_Typing/01_Boundaries/01_Watershed/LittleMissouri_Watershed.shp"
dem_in = arcpy.GetParameterAsText(
    5)  # projected DEMs folder: "D:/PYDEM/Proj_DEM2/"
dem_out = arcpy.GetParameterAsText(
    6)  # Clipped DEM:"D:/PYDEM/GDB/DEM_Test.tif"
hill_out = arcpy.GetParameterAsText(
    7)  # Hillshade: "D:/PYDEM/GDB/Hill_Test.tif"

# Process: Create File GDB
arcpy.CreateFileGDB_management(gdb_path, gdb_name)

arcpy.AddMessage("File geodatabase created!")

# Process: Create Mosaic Dataset
arcpy.CreateMosaicDataset_management(gdb_path + "\\" + gdb_name,
                                     mosaic_dataset, mosaic_cs, "1",
                                     "32_BIT_FLOAT", "NONE", "")

arcpy.AddMessage("Mosaic dataset created!")
arcpy.AddMessage("Adding rasters to mosaic dataset")

# Process: Add Rasters To Mosaic Dataset
arcpy.env.workspace = dem_in
dem_list = arcpy.ListRasters()
for raster in dem_list:
    arcpy.AddMessage("Adding " + raster + " to mosaic dataset")
    arcpy.AddRastersToMosaicDataset_management(
        gdb_path + "\\" + gdb_name + "\\" + mosaic_dataset, "Raster Dataset",
        raster)

# Process: Clip DEM
Exemplo n.º 24
0
def execute(request):
    """Mosaics input raster datasets into a new raster dataset or mosaic dataset.
    :param request: json as a dict.
    """
    status_writer = status.Writer()
    parameters = request['params']
    target_workspace = task_utils.get_parameter_value(parameters, 'target_workspace', 'value')
    output_name = task_utils.get_parameter_value(parameters, 'output_dataset_name', 'value')
    out_coordinate_system = task_utils.get_parameter_value(parameters, 'output_projection', 'code')
    # Advanced options
    output_raster_format = task_utils.get_parameter_value(parameters, 'raster_format', 'value')
    compression_method = task_utils.get_parameter_value(parameters, 'compression_method', 'value')
    compression_quality = task_utils.get_parameter_value(parameters, 'compression_quality', 'value')
    arcpy.env.compression = '{0} {1}'.format(compression_method, compression_quality)

    if output_raster_format in ('FileGDB', 'MosaicDataset'):
        if not os.path.splitext(target_workspace)[1] in ('.gdb', '.mdb', '.sde'):
            status_writer.send_state(status.STAT_FAILED, _('Target workspace must be a geodatabase'))
            return

    task_folder = request['folder']
    if not os.path.exists(task_folder):
        os.makedirs(task_folder)

    clip_area = None
    if not output_raster_format == 'MosaicDataset':
        # Get the clip region as an extent object.
        try:
            clip_area_wkt = task_utils.get_parameter_value(parameters, 'processing_extent', 'wkt')
            if not clip_area_wkt:
                clip_area_wkt = 'POLYGON ((-180 -90, -180 90, 180 90, 180 -90, -180 -90))'
            if not out_coordinate_system == '0':
                clip_area = task_utils.get_clip_region(clip_area_wkt, out_coordinate_system)
            else:
                clip_area = task_utils.get_clip_region(clip_area_wkt)
        except KeyError:
            pass

    status_writer.send_status(_('Setting the output workspace...'))
    if not os.path.exists(target_workspace):
        status_writer.send_state(status.STAT_FAILED, _('Target workspace does not exist'))
        return
    arcpy.env.workspace = target_workspace

    status_writer.send_status(_('Starting to process...'))
    num_results, response_index = task_utils.get_result_count(parameters)
    raster_items = None
    if num_results > task_utils.CHUNK_SIZE:
        # Query the index for results in groups of 25.
        query_index = task_utils.QueryIndex(parameters[response_index])
        fl = query_index.fl
        query = '{0}{1}{2}'.format(sys.argv[2].split('=')[1], '/select?&wt=json', fl)
        fq = query_index.get_fq()
        if fq:
            groups = task_utils.grouper(range(0, num_results), task_utils.CHUNK_SIZE, '')
            query += fq
        elif 'ids' in parameters[response_index]:
            groups = task_utils.grouper(list(parameters[response_index]['ids']), task_utils.CHUNK_SIZE, '')
        else:
            groups = task_utils.grouper(range(0, num_results), task_utils.CHUNK_SIZE, '')

        headers = {'x-access-token': task_utils.get_security_token(request['owner'])}
        for group in groups:
            if fq:
                results = requests.get(query + "&rows={0}&start={1}".format(task_utils.CHUNK_SIZE, group[0]), headers=headers)
            elif 'ids' in parameters[response_index]:
                results = requests.get(query + '{0}&ids={1}'.format(fl, ','.join(group)), headers=headers)
            else:
                results = requests.get(query + "&rows={0}&start={1}".format(task_utils.CHUNK_SIZE, group[0]), headers=headers)

            input_items = task_utils.get_input_items(results.json()['response']['docs'])
            if not input_items:
                input_items = task_utils.get_input_items(parameters[response_index]['response']['docs'])
            raster_items, pixels, bands, skipped = get_items(input_items)
    else:
        input_items = task_utils.get_input_items(parameters[response_index]['response']['docs'])
        raster_items, pixels, bands, skipped = get_items(input_items)

    if not raster_items:
        if skipped == 0:
            status_writer.send_state(status.STAT_FAILED, _('Invalid input types'))
            skipped_reasons['All Items'] = _('Invalid input types')
            task_utils.report(os.path.join(request['folder'], '__report.json'), len(raster_items), num_results, skipped_details=skipped_reasons)
            return
        else:
            status_writer.send_state(status.STAT_WARNING, _('{0} results could not be processed').format(skipped))
            task_utils.report(os.path.join(request['folder'], '__report.json'), len(raster_items), skipped, skipped_details=skipped_reasons)
            return

    # Get most common pixel type.
    pixel_type = pixel_types[max(set(pixels), key=pixels.count)]
    if output_raster_format in ('FileGDB', 'GRID', 'MosaicDataset'):
        output_name = arcpy.ValidateTableName(output_name, target_workspace)
    else:
        output_name = '{0}.{1}'.format(arcpy.ValidateTableName(output_name, target_workspace), output_raster_format.lower())

    if arcpy.Exists(os.path.join(target_workspace, output_name)):
        status_writer.send_state(status.STAT_FAILED, _('Output dataset already exists.'))
        return

    if output_raster_format == 'MosaicDataset':
        try:
            status_writer.send_status(_('Generating {0}. Large input {1} will take longer to process.'.format('Mosaic', 'rasters')))
            if out_coordinate_system == '0':
                out_coordinate_system = raster_items[0]
            else:
                out_coordinate_system = None
            mosaic_ds = arcpy.CreateMosaicDataset_management(target_workspace,
                                                             output_name,
                                                             out_coordinate_system,
                                                             max(bands),
                                                             pixel_type)
            arcpy.AddRastersToMosaicDataset_management(mosaic_ds, 'Raster Dataset', raster_items)
            arcpy.MakeMosaicLayer_management(mosaic_ds, 'mosaic_layer')
            layer_object = arcpy.mapping.Layer('mosaic_layer')
            task_utils.make_thumbnail(layer_object, os.path.join(request['folder'], '_thumb.png'))
        except arcpy.ExecuteError:
            skipped += 1
            skipped_reasons['All Items'] = arcpy.GetMessages(2)
    else:
        try:
            if len(bands) > 1:
                status_writer.send_state(status.STAT_FAILED, _('Input rasters must have the same number of bands'))
                return
            if out_coordinate_system == '0':
                out_coordinate_system = None
            status_writer.send_status(_('Generating {0}. Large input {1} will take longer to process.'.format('Mosaic', 'rasters')))
            if clip_area:
                ext = '{0} {1} {2} {3}'.format(clip_area.XMin, clip_area.YMin, clip_area.XMax, clip_area.YMax)
                tmp_mosaic = arcpy.MosaicToNewRaster_management(
                    raster_items,
                    target_workspace,
                    'tmpMosaic',
                    out_coordinate_system,
                    pixel_type,
                    number_of_bands=bands.keys()[0]
                )
                status_writer.send_status(_('Clipping...'))
                out_mosaic = arcpy.Clip_management(tmp_mosaic, ext, output_name)
                arcpy.Delete_management(tmp_mosaic)
            else:
                out_mosaic = arcpy.MosaicToNewRaster_management(raster_items,
                                                                target_workspace,
                                                                output_name,
                                                                out_coordinate_system,
                                                                pixel_type,
                                                                number_of_bands=bands.keys()[0],
                                                                mosaic_method='BLEND')
            arcpy.MakeRasterLayer_management(out_mosaic, 'mosaic_layer')
            layer_object = arcpy.mapping.Layer('mosaic_layer')
            task_utils.make_thumbnail(layer_object, os.path.join(request['folder'], '_thumb.png'))
        except arcpy.ExecuteError:
            skipped += 1
            skipped_reasons['All Items'] = arcpy.GetMessages(2)

    # Update state if necessary.
    if skipped > 0:
        status_writer.send_state(status.STAT_WARNING, _('{0} results could not be processed').format(skipped))
    task_utils.report(os.path.join(request['folder'], '__report.json'), len(raster_items), skipped, skipped_details=skipped_reasons)
Exemplo n.º 25
0
def createQARasterMosaicDataset(md_name, gdb_path, spatial_reference, input_folder, mxd, footprint_path=None, lasd_boundary_path=None):
    #Utility.printArguments(["md_name", "gdb_path", "spatial_reference", "input_folder", "mxd", "footprint_path", "lasd_boundary_path"],
    #                       [md_name, gdb_path, spatial_reference, input_folder, mxd, footprint_path, lasd_boundary_path], "A04_C CreateQARasterMosaicDatasets")

    md_path = os.path.join(gdb_path, md_name)

    a = datetime.datetime.now()

    if arcpy.Exists(md_path):
        arcpy.AddMessage("\tMD Exists: {}".format(md_path))
    else:
        try:
            raster_count = 0
            #arcpy.AddMessage("\t\tLooking for rasters to add to {} in folder {}".format(md_path, input_folder))
            for root, dirs, files in os.walk(input_folder):  # @UnusedVariable
                for f in files:
                    if f.upper().endswith(".TIF"):
                        raster_count = raster_count+1

            if raster_count <=0:
                arcpy.AddMessage("\t\tNo rasters to add to {} in folder {}".format(md_path, input_folder))
            else:
                arcpy.AddMessage("\t\tLooking for rasters to add to {} in folder {}".format(md_path, input_folder))
                # Create a MD in same SR as LAS Dataset
                arcpy.CreateMosaicDataset_management(in_workspace=gdb_path,
                                                     in_mosaicdataset_name=md_name,
                                                     coordinate_system=spatial_reference,
                                                     num_bands="",
                                                     pixel_type="",
                                                     product_definition="NONE",
                                                     product_band_definitions="")

                arcpy.SetMosaicDatasetProperties_management(in_mosaic_dataset=md_path, rows_maximum_imagesize="4100", columns_maximum_imagesize="15000", allowed_compressions="None;JPEG;LZ77;LERC", default_compression_type="LERC", JPEG_quality="75", LERC_Tolerance="0.01", resampling_type="CUBIC", clip_to_footprints="NOT_CLIP", footprints_may_contain_nodata="FOOTPRINTS_DO_NOT_CONTAIN_NODATA", clip_to_boundary="CLIP", color_correction="NOT_APPLY", allowed_mensuration_capabilities="Basic", default_mensuration_capabilities="Basic", allowed_mosaic_methods="NorthWest;Center;LockRaster;ByAttribute;Nadir;Viewpoint;Seamline;None", default_mosaic_method="NorthWest", order_field="", order_base="", sorting_order="ASCENDING", mosaic_operator="FIRST", blend_width="10", view_point_x="600", view_point_y="300", max_num_per_mosaic="2000", cell_size_tolerance="0.8", cell_size="10 10", metadata_level="BASIC", transmission_fields="Name;MinPS;MaxPS;LowPS;HighPS;Tag;GroupName;ProductName;CenterX;CenterY;ZOrder;Shape_Length;Shape_Area;Thumbnail", use_time="DISABLED", start_time_field="", end_time_field="", time_format="", geographic_transform="", max_num_of_download_items="20", max_num_of_records_returned="1000", data_source_type="GENERIC", minimum_pixel_contribution="1", processing_templates="None", default_processing_template="None", time_interval="", time_interval_units="")
                a = doTime(a, "\t\tCreated MD {}".format(md_name))

                arcpy.AddRastersToMosaicDataset_management(in_mosaic_dataset=md_path,
                                                           raster_type="Raster Dataset",
                                                           input_path=input_folder,
                                                           update_cellsize_ranges="UPDATE_CELL_SIZES",
                                                           update_boundary="UPDATE_BOUNDARY",
                                                           update_overviews="NO_OVERVIEWS",
                                                           maximum_pyramid_levels="",
                                                           maximum_cell_size="0",
                                                           minimum_dimension="150",
                                                           spatial_reference="",
                                                           filter="#",
                                                           sub_folder="SUBFOLDERS",
                                                           duplicate_items_action="EXCLUDE_DUPLICATES",
                                                           build_pyramids="BUILD_PYRAMIDS",
                                                           calculate_statistics="CALCULATE_STATISTICS",
                                                           build_thumbnails="BUILD_THUMBNAILS",
                                                           operation_description="#",
                                                           force_spatial_reference="NO_FORCE_SPATIAL_REFERENCE",
                                                           estimate_statistics="ESTIMATE_STATISTICS",
                                                           aux_inputs="")

                total_rows = int(arcpy.GetCount_management(md_path).getOutput(0))
                if total_rows <= 0:
                    arcpy.AddWarning("No rasters found for '{}'".format(md_path))
                    deleteFileIfExists(md_path, True)
                else:
                    try:
                        importMosaicDatasetGeometries(md_path, footprint_path, lasd_boundary_path)
                    except:
                        arcpy.AddWarning("Failed to update MD boundaries for '{}'".format(md_path))

                a = doTime(a, "\tAdded Rasters to MD {}".format(md_name))


        except:
            arcpy.AddWarning("Failed to create MD for QA Raster Layer '{}'. Please remove any locks and delete related intermediate files".format(md_path))

    return [md_path, md_name]
    ##==============================================================================
    # For each variable create a filegeodatabase and a mosaic dataset
    # Add rasters to mosaic dataset, calculate statistics
    # Add time field and add index

    ncTimeTableView = ncTimeDim + "TableView"
    result = arcpy.MakeNetCDFTableView_md(inNetCDFFile, ncTimeDim,
                                          ncTimeTableView, ncTimeDim)

    for ncVar in ncVarsXYTimeDim:
        ncVarFolderPath = scratchPath + os.sep + ncVar.lower()

        result = arcpy.CreateFileGDB_management(outPath, ncVar)
        fgdbPath = outPath + os.sep + ncVar + ".gdb"
        result = arcpy.CreateMosaicDataset_management(fgdbPath, ncVar, spRef)
        mosaicDatasetPath = fgdbPath + os.sep + ncVar

        result = arcpy.SetMosaicDatasetProperties_management(
            mosaicDatasetPath, "", "", "", "", "", "", "", "", "", "", "", "",
            "", "", "", "", "", "", "", "", ncTimeDimSize)
        result = arcpy.AddRastersToMosaicDataset_management(
            mosaicDatasetPath, "Raster Dataset", ncVarFolderPath)
        del ncVarFolderPath
        result = arcpy.CalculateStatistics_management(mosaicDatasetPath)

        mosaicTableView = ncVar + "TableView"
        result = arcpy.MakeTableView_management(mosaicDatasetPath,
                                                mosaicTableView)
        result = arcpy.JoinField_management(mosaicTableView, "OBJECTID",
                                            ncTimeTableView, "OID", ncTimeDim)
procLog = arcpy.GetParameterAsText(
    6)  #Log to store data on the mosaicking progress

# Open processing log.
Log = open(procLog, 'w+')
timeStamp = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
Log.write('Solar radiation mosaic creation started %s.\n' % timeStamp)

# Local variables:
coordSys = arcpy.Describe(inFprints).spatialReference

# Process: Create Mosaic Dataset
# This creates the blank (empty) mosaic dataset
arcpy.AddMessage('Creating empty mosaic dataset...')
md = 'md_' + mosaicName
solarMosaic = arcpy.CreateMosaicDataset_management(scratchGDB, md, coordSys)

# Loop through the geodatabases and add rasters to the mosaic dataset
for gdb in inGDB.split(';'):
    try:
        # Process: Add Rasters To Mosaic Dataset
        arcpy.AddMessage('Adding rasters from %s to mosaic dataset...' % gdb)
        arcpy.AddRastersToMosaicDataset_management(
            solarMosaic, "Raster Dataset", gdb, "UPDATE_CELL_SIZES",
            "UPDATE_BOUNDARY", "NO_OVERVIEWS", "", "0", "1500", "", "",
            "SUBFOLDERS", "OVERWRITE_DUPLICATES", "NO_PYRAMIDS",
            "NO_STATISTICS", "NO_THUMBNAILS", "", "NO_FORCE_SPATIAL_REFERENCE")
        Log.write('Successfully added rasters from %s to mosaic dataset. \n' %
                  gdb)
    except:
        arcpy.AddWarning('Failed to add rasters from %s.' % gdb)
Exemplo n.º 28
0
    agroRasters = list(r)[1:]
f.close()

Rasters = []
for i in range(0, len(agroRasters)):
    Rasters.append(agroRasters[i][0])

arcpy.AddMessage("Creating mosaic dataset...")

# Create Mosaic Dataset
try:
    if arcpy.Exists(agroMosaic):
        print agroMosaic, "exists, will be deleted"
        arcpy.DeleteMosaicDataset_management(agroMosaic)

    arcpy.CreateMosaicDataset_management(env.workspace, agroMosaic, Proj, "1",
                                         "32_BIT_SIGNED", "NONE", "")
    print "New mosaic dataset", agroMosaic, "was created\nAdding", len(
        agroRasters), "rasters to mosaic dataset..."
    arcpy.AddRastersToMosaicDataset_management(
        agroMosaic, "Raster Dataset", Rasters, "UPDATE_CELL_SIZES",
        "UPDATE_BOUNDARY", "NO_OVERVIEWS", "", "0", "1500", Proj, "",
        "SUBFOLDERS", "OVERWRITE_DUPLICATES", "NO_PYRAMIDS",
        "CALCULATE_STATISTICS", "NO_THUMBNAILS", "",
        "NO_FORCE_SPATIAL_REFERENCE")
    arcpy.GetMessages()
except Exception as e:
    print e.message

arcpy.AddMessage("Adding required fields...")  # Add required fields

for field in fields[2:]:  # exclude "Name" and "GroupName"
# Local variables:
CTX_Mosaic_Rasters = OUTPUT_FOLDER
CTX_Mosaic_NoDATA = CTX_Mosaic_Rasters
CTX_Mosaic_Footprints1 = CTX_Mosaic_NoDATA
CTX_Mosaic_Footprints2 = CTX_Mosaic_Footprints1
CTX_Final = CTX_Mosaic_Footprints2
CTXmosaic_GBD_gdb = OUTPUT_FOLDER
CTX_Mosaic_Init = CTXmosaic_GBD_gdb
CompleteDownload = "true"
ExpressionTF = "CompleteDown = \"false\""

# Process: Create File GDB
arcpy.CreateFileGDB_management(OUTPUT_FOLDER, MosaicName, "CURRENT")

# Process: Create Mosaic Dataset
arcpy.CreateMosaicDataset_management(CTXmosaic_GBD_gdb, MosaicName, "PROJCS['Mars_Equi180',GEOGCS['GCS_Mars_2000_Sphere',DATUM['D_Mars_2000_Sphere',SPHEROID['Mars_2000_Sphere_IAU_IAG',3396190.0,0.0]],PRIMEM['Reference_Meridian',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Equidistant_Cylindrical'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',180.0],UNIT['Meter',1.0]];-10669600 -16102700 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision", "1", "8_BIT_UNSIGNED", "NONE", "")

# Process: Add Rasters To Mosaic Dataset
arcpy.AddRastersToMosaicDataset_management(CTX_Mosaic_Init, "Raster Dataset", "C:\\Users\\thare\\Documents\\GIT\\ArcGIS_Plugins\\CTX_CreateMosaic_fromASU", "UPDATE_CELL_SIZES", "UPDATE_BOUNDARY", "NO_OVERVIEWS", "", "0", "1500", "", "*.JP2", "NO_SUBFOLDERS", "EXCLUDE_DUPLICATES", "NO_PYRAMIDS", "CALCULATE_STATISTICS", "NO_THUMBNAILS", "", "NO_FORCE_SPATIAL_REFERENCE")

# Process: Define Mosaic Dataset NoData
arcpy.DefineMosaicDatasetNoData_management(CTX_Mosaic_Rasters, "1", "BAND_1 0", "", "", "NO_COMPOSITE_NODATA")

# Process: BuildFootprints_1
arcpy.BuildFootprints_management(CTX_Mosaic_NoDATA, "", "RADIOMETRY", "1", "255", "10", "500", "NO_MAINTAIN_EDGES", "SKIP_DERIVED_IMAGES", "NO_BOUNDARY", "2000", "100", "NONE", "", "20", "0.05")

# Process: BuildFootprints_2
arcpy.BuildFootprints_management(CTX_Mosaic_Footprints1, "", "NONE", "1", "254", "10", "5000", "NO_MAINTAIN_EDGES", "SKIP_DERIVED_IMAGES", "UPDATE_BOUNDARY", "2000", "100", "NONE", "", "20", "0.05")

# Process: Set Mosaic Dataset Properties
arcpy.SetMosaicDatasetProperties_management(CTX_Mosaic_Footprints2, "4100", "15000", "None;LZ77;JPEG;LERC", "None", "75", "0", "BILINEAR", "CLIP", "FOOTPRINTS_MAY_CONTAIN_NODATA", "CLIP", "NOT_APPLY", "", "NONE", "Center;NorthWest;LockRaster;ByAttribute;Nadir;Viewpoint;Seamline;None", "Seamline", "", "", "ASCENDING", "BLEND", "10", "600", "300", "1000", "0.8", "", "FULL", "", "DISABLED", "", "", "", "", "20", "1000", "GENERIC", "1")
Exemplo n.º 30
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")