Skip to content

Instantly share code, notes, and snippets.

@felixerdy
Created August 22, 2017 11:52
Show Gist options
  • Save felixerdy/3ae702a20e265d9fdc48d42850f3190c to your computer and use it in GitHub Desktop.
Save felixerdy/3ae702a20e265d9fdc48d42850f3190c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# add_rasters.py
# Created on: 2017-07-11 11:46:51.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
import re
import os
# Set the necessary product code
#import arceditor
# Import arcpy module
import arcpy
# Local variables:
MaxPS = 10000
update_boundary = True
mosaData ="C:/geodatabase/copi.gdb/waterdetect"
#inputPath = '''joblist'''
#filepath = '''joblist Dateiname'''
duplicate_items_action = 'EXCLUDE_DUPLICATES'
def getTimeFromPath(filepath):
# find first 8 following digits
date = re.search(r"\d{8}", filepath)
time = ''
# if regex search was successful
if date:
# save search result
time = date.group(0)
else:
# get date path manually
time = filepath[19:27]
# building date string
day = time[6:8]
month = time[4:6]
year = time[0:4]
time = month + "/" + day + "/" + year
return time
def addAndProcessMosaic(fileName):
filepath = 'C:\\geodatabase\\MRF\\' + fileName
print filepath
# Process: Add Rasters To Mosaic Dataset
arcpy.AddRastersToMosaicDataset_management(mosaData, "Raster Dataset", filepath, '', update_boundary, '', '', '', '', '', '', '', duplicate_items_action)
# Update Raster Fields - add time
Expression = "Name= '"+fileName.split('.mrf')[0]+"'"
message_count = arcpy.GetMessageCount()
last_message = arcpy.GetMessage(message_count - 1)
if 'Succeeded' in last_message:
rows = arcpy.UpdateCursor(mosaData, Expression)
for r in rows:
r.Time = getTimeFromPath(filepath)
r.MaxPS = MaxPS
rows.updateRow(r)
del rows
@felixerdy
Copy link
Author

Developed by @marikemau, @nsteffens, @mdragunski, @JanVan01 and me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment