Example #1
0
 def update_mosaic_statistics(self, mosaic_dataset):
     logger.debug('updating mosaic statistics')
     try:
         arcpy.SetMosaicDatasetProperties_management(
             mosaic_dataset,
             use_time="ENABLED",
             start_time_field='start_date',
             end_time_field='end_date')
     except Exception, e:
         logger.debug('Set Mosaic Dataset Properties failed for {0}'.format(
             mosaic_dataset))
Example #2
0
def update_mosaic_statistics(mosaic_dataset):
    logging.debug('updating mosaic statistics')
    arcpy.SetMosaicDatasetProperties_management(
        mosaic_dataset,
        use_time="ENABLED",
        start_time_field="start_date",
        end_time_field="end_date",
    )
    arcpy.management.CalculateStatistics(mosaic_dataset)
    arcpy.management.BuildPyramidsandStatistics(mosaic_dataset,
                                                'INCLUDE_SUBDIRECTORIES',
                                                'BUILD_PYRAMIDS',
                                                'CALCULATE_STATISTICS')
    arcpy.RefreshCatalog(mosaic_dataset)
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")

# Process: Calculate Value
arcpy.CalculateValue_management(ExpressionTF, "", "Boolean")

Example #4
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]
    # 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)
        result = arcpy.AddIndex_management(mosaicDatasetPath, ncTimeDim,
                                           ncTimeDim, "UNIQUE", "ASCENDING")
        print "Done with variable " + ncVar  #NSN:REMOVE
Example #6
0
    def setMDProperties(self, mdPath):

        mdName = os.path.basename(mdPath).upper()

        noRasterPerMosaic = self.getInternalPropValue(
            mdName, 'max_num_per_mosaic')  #"50"
        maxRequestSizex = self.getInternalPropValue(
            mdName, 'rows_maximum_imagesize')  #"4000"
        maxRequestSizey = self.getInternalPropValue(
            mdName, 'columns_maximum_imagesize')  #"4000"
        allowedCompression = self.getInternalPropValue(
            mdName, 'allowed_compressions')  #"LZ77;NONE;JPEG;LERC"
        defaultCompression = self.getInternalPropValue(
            mdName, 'default_compression_type')  #"None"
        compressionQuality = self.getInternalPropValue(mdName,
                                                       'JPEG_quality')  #"75"
        clipToFootprint = self.getInternalPropValue(
            mdName, 'clip_to_footprints')  #"NOT_CLIP"
        allowedFields = self.getInternalPropValue(
            mdName, 'transmission_fields'
        )  #"Name;MinPS;MaxPS;LowPS;HighPS;ProductName;BEST;Source;LE90;CE90;Date_Start;Date_End;Source_URL;DEM_Type;Dataset_ID;VerticalDatum"
        LERC_Tolerance = self.getInternalPropValue(mdName,
                                                   'LERC_Tolerance')  #"0.01"
        resampling_type = self.getInternalPropValue(mdName, 'resampling_type')
        clip_to_boundary = self.getInternalPropValue(mdName,
                                                     'clip_to_boundary')
        color_correction = self.getInternalPropValue(mdName,
                                                     'color_correction')
        footprints_may_contain_nodata = self.getInternalPropValue(
            mdName, 'footprints_may_contain_nodata')
        allowed_mensuration_capabilities = self.getInternalPropValue(
            mdName, 'allowed_mensuration_capabilities')
        default_mensuration_capabilities = self.getInternalPropValue(
            mdName, 'default_mensuration_capabilities')
        allowed_mosaic_methods = self.getInternalPropValue(
            mdName, 'allowed_mosaic_methods')
        defaultMosaicMethod = self.getInternalPropValue(
            mdName, 'default_mosaic_method')
        orderField = self.getInternalPropValue(mdName, 'Order_field')
        order_base = self.getInternalPropValue(mdName, 'order_base')
        sorting_order = self.getInternalPropValue(mdName, 'sorting_order')
        mosaic_operator = self.getInternalPropValue(mdName, 'mosaic_operator')
        blend_width = self.getInternalPropValue(mdName, 'blend_width')
        view_point_x = self.getInternalPropValue(mdName, 'view_point_x')
        view_point_y = self.getInternalPropValue(mdName, 'view_point_y')
        cell_size_tolerance = self.getInternalPropValue(
            mdName, 'cell_size_tolerance')
        cell_size = self.getInternalPropValue(mdName, 'cell_size')
        metadata_level = self.getInternalPropValue(mdName, 'metadata_level')
        use_time = self.getInternalPropValue(mdName, 'use_time')
        start_time_field = self.getInternalPropValue(mdName,
                                                     'start_time_field')
        end_time_field = self.getInternalPropValue(mdName, 'end_time_field')
        time_format = self.getInternalPropValue(mdName, 'time_format')
        geographic_transform = self.getInternalPropValue(
            mdName, 'geographic_transform')
        max_num_of_download_items = self.getInternalPropValue(
            mdName, 'max_num_of_download_items')
        max_num_of_records_returned = self.getInternalPropValue(
            mdName, 'max_num_of_records_returned')

        is_10_3_plus = self.CheckMDCSVersion([10, 3, 0, 4321], [0, 0, 0, 0],
                                             False)

        if (self.is101SP1() == False
            ):  #OrderField set to 'BEST' would fail in 10.1 without SP1
            orderField = 'MinPS'

        try:
            self.log("\t\tSetting MD Properties : ", self.const_general_text)
            #if dversion > 10304320:
            if (is_10_3_plus == True):
                data_source_type = self.getInternalPropValue(
                    mdName, 'data_source_type')
                minimum_pixel_contribution = self.getInternalPropValue(
                    mdName, 'minimum_pixel_contribution')
                processing_templates = self.getInternalPropValue(
                    mdName, 'processing_templates')
                default_processing_template = self.getInternalPropValue(
                    mdName, 'default_processing_template')

                arcpy.SetMosaicDatasetProperties_management(
                    mdPath, maxRequestSizex, maxRequestSizey,
                    allowedCompression, defaultCompression, compressionQuality,
                    LERC_Tolerance, resampling_type, clipToFootprint,
                    footprints_may_contain_nodata, clip_to_boundary,
                    color_correction, allowed_mensuration_capabilities,
                    default_mensuration_capabilities, allowed_mosaic_methods,
                    defaultMosaicMethod, orderField, order_base, sorting_order,
                    mosaic_operator, blend_width, view_point_x, view_point_y,
                    noRasterPerMosaic, cell_size_tolerance, cell_size,
                    metadata_level, allowedFields, use_time, start_time_field,
                    end_time_field, time_format, geographic_transform,
                    max_num_of_download_items, max_num_of_records_returned,
                    data_source_type, minimum_pixel_contribution,
                    processing_templates, default_processing_template)

            else:
                arcpy.SetMosaicDatasetProperties_management(
                    mdPath, maxRequestSizex, maxRequestSizey,
                    allowedCompression, defaultCompression, compressionQuality,
                    LERC_Tolerance, resampling_type, clipToFootprint,
                    footprints_may_contain_nodata, clip_to_boundary,
                    color_correction, allowed_mensuration_capabilities,
                    default_mensuration_capabilities, allowed_mosaic_methods,
                    defaultMosaicMethod, orderField, order_base, sorting_order,
                    mosaic_operator, blend_width, view_point_x, view_point_y,
                    noRasterPerMosaic, cell_size_tolerance, cell_size,
                    metadata_level, allowedFields, use_time, start_time_field,
                    end_time_field, time_format, geographic_transform,
                    max_num_of_download_items, max_num_of_records_returned)
            self.log(
                "\t\tDone setting mosaic dataset properties for : " + mdName,
                self.const_general_text)
            return True

        except:
            self.log("Failed to set mosaic dataset properties.",
                     self.const_critical_text)
            self.log(arcpy.GetMessages(), self.const_critical_text)

        return False
Example #7
0
def processJob(ProjectJob, project, ProjectUID, masterParentDir,
               masterService):
    masterServiceFolder = None
    masterName = masterService
    index = masterService.find("/")
    if index < 0:
        index = masterService.find("\\")

    if index >= 0:
        masterServiceFolder = masterService[0:index]
        masterName = masterService[index + 1:]

    master_md_name = masterName  # RasterConfig.MASTER_MD_NAME

    Utility.printArguments(["Master Folder", "Master Name", "Master MD Name"],
                           [masterServiceFolder, masterName, master_md_name],
                           "A08 AddPrjectToMaster")

    ProjectFolder = ProjectFolders.getProjectFolderFromDBRow(
        ProjectJob, project)
    #         projectID = ProjectJob.getProjectID(project)

    ProjectMDs_fgdb_path = ProjectFolder.published.fgdb_path
    arcpy.AddMessage("Project file GDB Path: {}".format(ProjectMDs_fgdb_path))
    # Don't need to do height models
    md_list = [
        FoldersConfig.DTM, FoldersConfig.DSM, FoldersConfig.DLM,
        FoldersConfig.INT
    ]

    # Ensure the master_md_path exists
    for md_name in md_list:

        projectMD_path = os.path.join(
            "{}_{}.gdb".format(ProjectMDs_fgdb_path[:-4], md_name), md_name)
        arcpy.AddMessage("Project {} Mosaic Dataset Path: {}".format(
            md_name, projectMD_path))

        if arcpy.Exists(projectMD_path):
            master_md_path = os.path.join(
                masterParentDir, masterService,
                "{}_{}.gdb".format(masterName, md_name), md_name)
            master_md_path = os.path.normpath(master_md_path)
            arcpy.AddMessage("Master {} MD Path: {}".format(
                md_name, master_md_path))

            if arcpy.Exists(master_md_path):
                #                     project_md_path = os.path.join(ProjectMDs_fgdb_path, md_name)
                #                     if arcpy.Exists(project_md_path):

                # Get a record count from the Master MD
                result = arcpy.GetCount_management(master_md_path)
                countMasterRasters = int(result.getOutput(0))
                arcpy.AddMessage(
                    "Before ingest Master Mosaic Dataset: {0} has {1} row(s)".
                    format(master_md_path, countMasterRasters))

                # #      # Get the maximum value of ItemTS From the Master Mosaic Dataset
                # #      #  The value of ItemTS is based on the last time the row was modified. Knowing
                # #      #  the current maximum value of ItemTS in the Master will help us determine which rows were
                # #      #  added as a result of the subsequent call to "Add Raster"
                # #      if countMasterRasters > 0:
                # #          fc = r"in_memory/MaxItemTS"
                # #          arcpy.Statistics_analysis(master_md_path,fc,statistics_fields="ItemTS MAX",case_field="#")
                # #
                # #          fields = ['MAX_ITEMTS']
                # #          with arcpy.da.SearchCursor(fc, fields) as cursor:
                # #              for row in cursor:
                # #                  MaxItemTSValue = float(row[0])
                # #      else:
                # #          MaxItemTSValue = 0.0
                # #
                # #      arcpy.AddMessage("Maximum value for ItemTS before adding Project MD rows to Master:       {0}".format(MaxItemTSValue))

                #                         project_md_path = project_md_path.strip("'")
                #                         # Ensure the project_md_path exists
                #                         if not arcpy.Exists(project_md_path):
                #                             arcpy.AddError("\nExiting: Project Mosaic Dataset doesn't exist: {0}".format(project_md_path))
                #                             continue

                # Get a record count from the Project MD just to be sure we have data to ingest
                result = arcpy.GetCount_management(projectMD_path)
                countProjRasters = int(result.getOutput(0))

                if countProjRasters > 0:
                    arcpy.AddMessage("{0} has {1} raster product(s).".format(
                        projectMD_path, countProjRasters))

                    # Gather project_md_path metadata such as spatial reference and cell size
                    descProjectMD = arcpy.Describe(projectMD_path)
                    descProjectMDSR = descProjectMD.SpatialReference
                    ProjectMDSpatialRef = descProjectMD.SpatialReference.exportToString(
                    )
                    arcpy.AddMessage("Ingesting: {0}".format(projectMD_path))
                    # arcpy.AddMessage("Spatial reference of the Project MD is: \n\n{0}\n".format(ProjectMDSpatialRef))
                    # arcpy.AddMessage("Length of SR string is {0}:".format(len(ProjectMDSpatialRef)))

                    # Ensure the project_md_path is 1-band 32-bit floating point (i.e. is an elevation raster)
                    bandCountresult = arcpy.GetRasterProperties_management(
                        projectMD_path,
                        property_type="BANDCOUNT",
                        band_index="")
                    bandCount = int(bandCountresult.getOutput(0))
                    if bandCount == 1:

                        bitDepthresult = arcpy.GetRasterProperties_management(
                            projectMD_path,
                            property_type="VALUETYPE",
                            band_index="")
                        bitDepth = int(bitDepthresult.getOutput(0))
                        if bitDepth == 9:

                            # Determine the cell size of the Project Mosaic Dataset
                            cellsizeResult = arcpy.GetRasterProperties_management(
                                projectMD_path,
                                property_type="CELLSIZEX",
                                band_index="")
                            cellsize = float(cellsizeResult.getOutput(0))
                            arcpy.AddMessage(
                                "Cell size of Project MD:  {0} {1}".format(
                                    cellsize, descProjectMDSR.linearUnitName))

                            # Add the rows from the Project MD to the Master MD using the
                            # Table raster type, and don't update the cell size ranges or the boundary
                            raster_type = "Table"
                            arcpy.AddRastersToMosaicDataset_management(
                                master_md_path,
                                raster_type,
                                projectMD_path,
                                update_cellsize_ranges="NO_CELL_SIZES",
                                update_boundary="NO_BOUNDARY",
                                update_overviews="NO_OVERVIEWS",
                                maximum_pyramid_levels="#",
                                maximum_cell_size="0",
                                minimum_dimension="1500",
                                spatial_reference=ProjectMDSpatialRef,
                                filter="#",
                                sub_folder="NO_SUBFOLDERS",
                                duplicate_items_action="ALLOW_DUPLICATES",
                                build_pyramids="NO_PYRAMIDS",
                                calculate_statistics="NO_STATISTICS",
                                build_thumbnails="NO_THUMBNAILS",
                                operation_description="#",
                                force_spatial_reference=
                                "NO_FORCE_SPATIAL_REFERENCE")
                            Utility.addToolMessages()
                            #                                 messages = arcpy.GetMessages()
                            #                                 arcpy.AddMessage("\nResults output from AddRastersToMosaicDataset are: \n{0}\n".format(messages))

                            # Get another record count from the Master MD
                            result = arcpy.GetCount_management(master_md_path)
                            countMasterRasters = int(result.getOutput(0))
                            arcpy.AddMessage(
                                "After ingest Master Mosaic Dataset: {0} has {1} row(s)"
                                .format(master_md_path, countMasterRasters))

                            # NOTE: The following section is commented, as setting Category to 2 for overviews created on the project_md_path doesn't work well
                            # #      # Reset Category to 2 for all overview records ingested from the Project MD (for some reason
                            # #      #   the table raster type sets all rows to Category of 1).
                            # #      where_clause = "ItemTS > " + str(MaxItemTSValue) + " AND UPPER(Name) LIKE 'OV_%'"
                            # #      arcpy.AddMessage("Mosaic Layer where clause: {0}".format(where_clause))
                            # #      arcpy.MakeMosaicLayer_management(master_md_path,"MasterMDLayer",where_clause,template="#",band_index="#",
                            # #                                       mosaic_method="BY_ATTRIBUTE",order_field="ProjectDate",order_base_value="3000",
                            # #                                       lock_rasterid="#",sort_order="ASCENDING",mosaic_operator="LAST",cell_size="1")
                            # #
                            # #      messages =  arcpy.GetMessages()
                            # #      arcpy.AddMessage("\nResults output from MakeMosaicLayer are: \n{0}\n".format(messages))
                            # #
                            # #      arcpy.CalculateField_management("MasterMDLayer", field="Category", expression="2", expression_type="VB", code_block="")
                            # #      messages =  arcpy.GetMessages()
                            # #      arcpy.AddMessage("\nResults output from CalculateField are: \n{0}\n".format(messages))

                            # Build the boundary
                            # NOTE: if the boundary has been set to a large shape, then APPEND should have no effect
                            #       on the existing boundary
                            #arcpy.BuildBoundary_management(master_md_path, where_clause="", append_to_existing="APPEND", simplification_method="NONE")

                            #messages = arcpy.GetMessages()
                            #arcpy.AddMessage("\nResults output from BuildBoundary are: \n{0}\n".format(messages))

                            # set mosaic properties on the master *AGAIN* to ensure that clip to footprint doesn't get re-set
                            #  Clip to footprint is somehow getting reset in 10.3.  It should be set so that footprints are NOT clipping data (NOT_CLIP)
                            transmissionFields = "Name;LowPS;CenterX;CenterY;Project_Date;Project_ID;area;el_type;format;h_name;h_unit;h_wkid;v_name;v_unit;cell_h;cell_w;height;width;nodata;pixel;unc_size;xmax;xmin;ymax;ymin;zdev;ZMax;zmean;ZMin;zran;Version;ra_pt_ct;ra_pt_sp;ra_zmax;ra_zmin;ra_zran;PointCount;PointSpacing;is_class;LAS_ZMax;LAS_ZMin"
                            arcpy.AddMessage(
                                "\ntransmissionFields: {0}".format(
                                    transmissionFields))

                            arcpy.SetMosaicDatasetProperties_management(
                                master_md_path,
                                rows_maximum_imagesize="25000",
                                columns_maximum_imagesize="25000",
                                allowed_compressions="LERC;JPEG;None;LZ77",
                                default_compression_type="LERC",
                                JPEG_quality="75",
                                LERC_Tolerance="0.001",
                                resampling_type="BILINEAR",
                                clip_to_footprints="NOT_CLIP",
                                footprints_may_contain_nodata=
                                "FOOTPRINTS_MAY_CONTAIN_NODATA",
                                clip_to_boundary="NOT_CLIP",
                                color_correction="NOT_APPLY",
                                allowed_mensuration_capabilities="#",
                                default_mensuration_capabilities="NONE",
                                allowed_mosaic_methods=
                                "NorthWest;Center;LockRaster;ByAttribute;Nadir;Viewpoint;Seamline;None",
                                default_mosaic_method="ByAttribute",
                                order_field=CMDRConfig.PROJECT_DATE,
                                order_base="3000",
                                sorting_order="ASCENDING",
                                mosaic_operator="FIRST",
                                blend_width="0",
                                view_point_x="600",
                                view_point_y="300",
                                max_num_per_mosaic="40",
                                cell_size_tolerance="0.8",
                                cell_size="1 1",
                                metadata_level="BASIC",
                                transmission_fields=transmissionFields,
                                use_time="DISABLED",
                                start_time_field=CMDRConfig.PROJECT_DATE,
                                end_time_field="#",
                                time_format="#",
                                geographic_transform="#",
                                max_num_of_download_items="40",
                                max_num_of_records_returned="2000",
                                data_source_type="ELEVATION",
                                minimum_pixel_contribution="1",
                                processing_templates="None",
                                default_processing_template="None")

                            messages = arcpy.GetMessages()
                            arcpy.AddMessage(
                                "\nResults output from SetMosaicDatasetProperties are: \n{0}\n"
                                .format(messages))

                            ## 20180505 EIronside: Removed overview generation because they were taking a long time and things seem to work ok without them.
                            ##                            # define the location of the mosaic dataset overviews
                            ##                            loc = master_md_path.rfind(".gdb")
                            ##                            # arcpy.AddMessage("loc = {0}".format(loc))
                            ##                            # MasterMD_overview_path = master_md_path[:loc] + r".Overviews" + master_md_path[loc+4:]
                            ##                            MasterMD_overview_path = master_md_path[:loc] + r".Overviews"
                            ##                            arcpy.AddMessage("Mosaic Dataset Overview Location: {0}".format(MasterMD_overview_path))

                            # Define and Build overviews

                            # Begin building service overviews at low scale (305.74811 Meters)

                            #cellsizeOVR = 305.74811
                            #see what happens without overviews...
                            #DefineBuildOverviews(cellsizeOVR, master_md_path, MasterMD_overview_path, projectMD_path)
                            ## 20180505 EIronside: Removed overview generation because they were taking a long time and things seem to work ok without them.

                            arcpy.Compact_management(
                                in_workspace=os.path.dirname(master_md_path))

                            arcpy.AddMessage(
                                "Completed Project Mosaic Dataset: {}\n\n".
                                format(projectMD_path))
                        else:
                            arcpy.AddWarning(
                                "\nProject Mosaic bit depth is not 32-bit Floating Point. Ingoring mosaic dataset."
                            )
                    else:
                        arcpy.AddWarning(
                            "Project band count is not 1 (expecting single band elevation data). Ingoring mosaic dataset."
                        )
                else:
                    arcpy.AddWarning(
                        "Count of rasters in project mosaic dataset is 0. Please add some rasters to the project."
                    )


#                     else:
#                         arcpy.AddWarning("Project Mosaic Dataset path is not found '{}'. Please create it before proceeding.".format(project_md_path))
            else:
                arcpy.AddError(
                    "Master Mosaic Dataset path is not found '{}'. Please create it before proceeding."
                    .format(master_md_path))
        else:
            arcpy.AddWarning(
                "Project Mosaic Dataset path is not found '{}'. Please create it before proceeding."
                .format(projectMD_path))
Example #8
0
        # Process: Add Rasters To Mosaic Dataset
        arcpy.AddMessage('Adding rasters from %s to mosaic dataset...' % gdb)
        arcpy.AddRastersToMosaicDataset_management(
            hydroMosaic, "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)
        Log.write('Failed to add rasters from %s to mosaic dataset. \n' % gdb)

# Process: Set mosaic properties
arcpy.SetMosaicDatasetProperties_management(
    md, '', '', '', '', '', '', 'NEAREST', 'NOT_CLIP',
    'FOOTPRINTS_DO_NOT_CONTAIN_NODATA', '', '', '', '', '', '', '', '', '',
    'MAX')

# Process: Copy final output raster dataset and build raster attribute table
try:
    arcpy.AddMessage(
        'Exporting final raster dataset.  This may take awhile...')
    rd = outGDB + os.sep + mosaicName
    arcpy.CopyRaster_management(hydroMosaic, rd)
    arcpy.BuildRasterAttributeTable_management(rd, 'OVERWRITE')
except:
    arcpy.AddWarning('Unable to export raster dataset.')
    Log.write('Unable to export to %s' % rd)

# Close processing log.
timeStamp = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
Example #9
0
        #Test_Script.pypython Test_Script.py -h Do nothing
    else:
        arcpy.CreateFileGDB_management(workspace_gdb, collection_id+".gdb")
        # Create Master Mosaic
        # Process: Mosaik-Dataset erstellen
        arcpy.CreateMosaicDataset_management(workspace_gdb+"\\" + collection_id + '.gdb', "Master" + '_' + collection_id,
                                                 "PROJCS['ETRS_1989_UTM_Zone_32N',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],"
                                                 "PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],"
                                                 "PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],"
                                                 "UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0,001;0,001;0,001;IsHighPrecision",pixel_type=product_pixel_type)
        print "Created Master Mosaic for " + collection_id
        arcpy.AddField_management(workspace_gdb+"\\"+collection_id + '.gdb\\' + 'Master' + "_" + collection_id, "startTime", "text")
        arcpy.AddField_management(workspace_gdb+"\\"+collection_id + '.gdb\\' + 'Master' + "_" + collection_id, "endTime", "text")
        print "Added field"
        arcpy.SetMosaicDatasetProperties_management(
                workspace_gdb+"\\" + collection_id + '.gdb\\' "Master" + '_' + collection_id,
                use_time="ENABLED", start_time_field="startTime", end_time_field="endTime",
                time_format="YYYY-MM-DD hh:mm:ss.s",time_interval=1.0, time_interval_units="Days")
        print "Mosaic Properties were set"
except arcpy.ExecuteError:
    e = sys.exc_info()[1]
    print(e.args[0])
    print arcpy.GetMessages() + "\n\n"
    sys.exit("Failed in creating GDB and MasterMosaic")


try:
    # Create MosaicDataset for every processed Rasterproduct
    # Add the belonging Rasterfile(TIF) to the created MosaicDataset
    mosaic_dataset_name = "T_" + product_name[:len(product_name)-4]+'_Mosaic'
    mosaic_product_name = mosaic_dataset_name.replace("-", "_")
    # Process: Mosaik-Dataset erstellen
Example #10
0
def CreateMasterMosaicDataset(master_fgdb_path, master_md_name, MDMasterFC_path, masterCellSize_meters):
    Utility.printArguments(["master_fgdb_path", "master_md_name", "MDMasterFC_path", "masterCellSize_meters"],
                           [master_fgdb_path, master_md_name, MDMasterFC_path, masterCellSize_meters], "B02 CreateMasterMosaicDataset")
    
    
    # Ensure the Master gdb exists
    if os.path.exists(master_fgdb_path):
        master_md_path = os.path.join(master_fgdb_path, master_md_name)
        arcpy.AddMessage("Full Master Mosaic Name:             {0}".format(master_md_path))
        
        if not arcpy.Exists(master_md_path):
            
                        
            # SpatRefMaster = "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],AUTHORITY['EPSG',3857]]"
            SpatRefMaster = RasterConfig.SpatRef_WebMercator
            
            # Create the Master Mosaic Dataset
            arcpy.CreateMosaicDataset_management(master_fgdb_path, master_md_name,
                                                 coordinate_system=SpatRefMaster,
                                                 num_bands="1", pixel_type="32_BIT_FLOAT", product_definition="NONE", product_band_definitions="#")
            Utility.addToolMessages()
            
            # If a boundary is specified (it is optional)...
            # Write one record to the boundary so it can be subsequently replaced by the import Mosaic Dataset Geometry tool
            addMasterBoundary(master_fgdb_path, master_md_name, MDMasterFC_path)
                        
            Raster.addStandardMosaicDatasetFields(md_path=master_md_path)
            
                        
                        
                        
                        
            
#                         arcpy.AddField_management(master_md_path, field_name="ProjectID", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="100", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="ProjectDate", field_type="DATE", field_precision="#", field_scale="#",
#                                                   field_length="#", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="RasterPath", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="512", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
# #                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="ProjectSrs", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="100", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="ProjectSrsUnits", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="20", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="ProjectSrsUnitsZ", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="20", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="ProjectSource", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="20", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
#                         arcpy.AddField_management(master_md_path, field_name="PCSCode", field_type="TEXT", field_precision="#", field_scale="#",
#                                                   field_length="20", field_alias="#", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="#")
#                         Utility.addToolMessages()
            
#                         arcpy.AddMessage("Creating Indexes on previously created fields in Master GDB...")
            
            # Create indexes on all metadata fields to facilitate query
            
#                         arcpy.AddIndex_management(master_md_path, fields="ProjectID", index_name="ProjectID", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
#                         arcpy.AddIndex_management(master_md_path, fields="ProjectDate", index_name="ProjectDate", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
#                         arcpy.AddIndex_management(master_md_path, fields="ProjectSrs", index_name="ProjectSrs", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
#                         arcpy.AddIndex_management(master_md_path, fields="ProjectSrsUnits", index_name="ProjectSrsUnits", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
#                         arcpy.AddIndex_management(master_md_path, fields="ProjectSrsUnitsZ", index_name="ProjectSrsUnitsZ", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
#                         arcpy.AddIndex_management(master_md_path, fields="ProjectSource", index_name="ProjectSource", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
#                         arcpy.AddIndex_management(master_md_path, fields="PCSCode", index_name="PCSCode", unique="NON_UNIQUE", ascending="ASCENDING")
#                         Utility.addToolMessages()
            
            # Set the desired Master MD properties (non-default parameters are listed below):
            #   default mosaic method is "BYATTRIBUTE" w ProjectDate
            #      order_base = 3000 (a year far into the future)
            #   default_compression_type="LERC"
            #   limited the transmission_fields
            #   start_time_field="ProjectDate" (in case we decide to enable time later)
            #   max_num_of_records_returned="2000" (default is 1000)
            #   max_num_of_download_items="40" (default is 20)
            #   max_num_per_mosaic = "40"      (default is 20)
            #   data_source_type="ELEVATION"
            #   cell_size = 1
            #   rows_maximum_imagesize="25000"
            #   columns_maximum_imagesize="25000"
            #   metadata_level = "BASIC"
            
            transmissionFields = CMDRConfig.TRANSMISSION_FIELDS
            arcpy.AddMessage("transmissionFields: {0}".format(transmissionFields))
            
            arcpy.AddRastersToMosaicDataset_management(in_mosaic_dataset=master_md_path, raster_type="Raster Dataset", input_path=RasterConfig.MasterTempRaster, update_cellsize_ranges="UPDATE_CELL_SIZES", update_boundary="UPDATE_BOUNDARY", update_overviews="NO_OVERVIEWS", maximum_pyramid_levels="", maximum_cell_size="0", minimum_dimension="1500", spatial_reference="", filter="#", sub_folder="SUBFOLDERS", duplicate_items_action="ALLOW_DUPLICATES", build_pyramids="NO_PYRAMIDS", calculate_statistics="NO_STATISTICS", build_thumbnails="NO_THUMBNAILS", operation_description="#", force_spatial_reference="NO_FORCE_SPATIAL_REFERENCE")
            Utility.addToolMessages()
            
            arcpy.SetMosaicDatasetProperties_management(master_md_path, rows_maximum_imagesize="25000", columns_maximum_imagesize="25000",
                                                      allowed_compressions="LERC;JPEG;None;LZ77", default_compression_type="LERC", JPEG_quality="75",
                                                      LERC_Tolerance="0.001", resampling_type="BILINEAR", clip_to_footprints="NOT_CLIP",
                                                      footprints_may_contain_nodata="FOOTPRINTS_MAY_CONTAIN_NODATA", clip_to_boundary="NOT_CLIP",
                                                      color_correction="NOT_APPLY", allowed_mensuration_capabilities="#",
                                                      default_mensuration_capabilities="NONE",
                                                      allowed_mosaic_methods="NorthWest;Center;LockRaster;ByAttribute;Nadir;Viewpoint;Seamline;None",
                                                      default_mosaic_method="ByAttribute", order_field=CMDRConfig.PROJECT_DATE, order_base="3000",
                                                      sorting_order="ASCENDING", mosaic_operator="FIRST", blend_width="0", view_point_x="600",
                                                      view_point_y="300", max_num_per_mosaic="40", cell_size_tolerance="0.8", cell_size="{0} {0}".format(masterCellSize_meters),
                                                      metadata_level="BASIC",
                                                      transmission_fields=transmissionFields,
                                                      use_time="DISABLED", start_time_field=CMDRConfig.PROJECT_DATE, end_time_field="#", time_format="#",
                                                      geographic_transform="#",
                                                      max_num_of_download_items="40", max_num_of_records_returned="2000",
                                                      data_source_type="ELEVATION", minimum_pixel_contribution="1", processing_templates="None",
                                                      default_processing_template="None")
            Utility.addToolMessages()
            
#             arcpy.SetMosaicDatasetProperties_management(in_mosaic_dataset="C:/temp/MDMaster/MDMaster_DSM.gdb/DSM", rows_maximum_imagesize="25000", columns_maximum_imagesize="25000", allowed_compressions="None;JPEG;LZ77;LERC", default_compression_type="None", JPEG_quality="75", LERC_Tolerance="0.001", resampling_type="BILINEAR", clip_to_footprints="NOT_CLIP", footprints_may_contain_nodata="FOOTPRINTS_MAY_CONTAIN_NODATA", clip_to_boundary="NOT_CLIP", color_correction="NOT_APPLY", allowed_mensuration_capabilities="#", default_mensuration_capabilities="NONE", allowed_mosaic_methods="ByAttribute;NorthWest;Center;LockRaster;Nadir;Viewpoint;Seamline;None", default_mosaic_method="ByAttribute", order_field="Project_Date", order_base="3000", sorting_order="ASCENDING", mosaic_operator="FIRST", blend_width="0", view_point_x="600", view_point_y="300", max_num_per_mosaic="40", cell_size_tolerance="0.8", cell_size="1 1", metadata_level="BASIC", transmission_fields="Name;MinPS;MaxPS;LowPS;HighPS;Tag;GroupName;ProductName;CenterX;CenterY;ZOrder;Shape_Length;Shape_Area;Project_ID;Project_Date;Porject_Source;Project_SR_XY;Project_SR_XY_Units;Project_SR_XY_Code;Project_SR_Z_Units", use_time="DISABLED", start_time_field="Project_Date", end_time_field="", time_format="", geographic_transform="", max_num_of_download_items="40", max_num_of_records_returned="2000", data_source_type="ELEVATION", minimum_pixel_contribution="1", processing_templates="None", default_processing_template="None")
            # set statistics Min = -300 and Max = 2000M
            # set nodata = default no data value
            arcpy.SetRasterProperties_management(master_md_path, data_type="ELEVATION", statistics="1 0 2000 # #", stats_file="#", nodata="1 {}".format(RasterConfig.NODATA_DEFAULT))
            Utility.addToolMessages()
            
            arcpy.RemoveRastersFromMosaicDataset_management(in_mosaic_dataset=master_md_path, where_clause="1=1", update_boundary="UPDATE_BOUNDARY", mark_overviews_items="MARK_OVERVIEW_ITEMS", delete_overview_images="DELETE_OVERVIEW_IMAGES", delete_item_cache="DELETE_ITEM_CACHE", remove_items="REMOVE_MOSAICDATASET_ITEMS", update_cellsize_ranges="UPDATE_CELL_SIZES")
            Utility.addToolMessages()
                        
        else:
            arcpy.AddWarning("Master Mosaic Dataset already exists: {0}. Cannot continue".format(master_md_path))
    else:
        arcpy.AddError("Master Geodatabase doesn't exist {0}".format(master_fgdb_path))
    
    arcpy.AddMessage("Operation complete")
Example #11
0
 def setproperties(self, **kwargs):
     arcpy.SetMosaicDatasetProperties_management(self.fname, **kwargs)
     DisplayMessages()