Skip to content

Instantly share code, notes, and snippets.

@OterLabb
OterLabb / distanceTo.py
Last active June 19, 2024 16:53
ArcGIS distanceTo script
import arcpy
# Variables
pointData = 'points' # Point dataset
distanceData = 'other_fc' # Distance to this dataset
arcpy.env.workspace = r'C:/Users/myUser/Documents/GIS/new_data.gdb'
# Create a new field name, and add it to pointData
distanceField = 'dis_' + distanceData[:4] # Gets first 4 letters of distanceData
arcpy.AddField_management(pointData, distanceField, 'FLOAT')
var fromJSON = [
{
"displayFieldName": "LID",
"fieldAliases": {
"Beskrivelse": "Beskrivelse"
},
"fields": [
{
"name": "Beskrivelse",
"type": "esriFieldTypeString",
@OterLabb
OterLabb / maketxt.py
Created June 10, 2018 08:22
Make a list of all jpg files in a folder
import os
files = [f for f in os.listdir('.') if os.path.isfile(f)]
cwd = os.getcwd()
text_file = open("images.txt", "w")
print("Writing to text file")
for f in files:
if "jpg" in f:
text_file.write(cwd + "\\" + f + '\n')
#text_file.close()
print("Done writing")
@OterLabb
OterLabb / parse_result.py
Created June 10, 2018 08:55
Parse result.txt from darknet
import os
from PIL import Image
from itertools import groupby, zip_longest, dropwhile
with open('result.txt') as fin:
stripped = (line.strip() for line in fin)
start_at = dropwhile(lambda L: not L.startswith('Enter'), stripped)
grouped = (list(g) for k, g in groupby(start_at, lambda L: L.startswith('Enter')))
for name, rest in zip_longest(*iter([grouped] * 2), fillvalue=[]):
if rest:
@OterLabb
OterLabb / datetime.py
Created June 23, 2018 16:30
Add date and time to DJI seamlines generated from agisoft photoscan in arcgis
import arcpy
import exifread
from datetime import datetime
# Variables
fc = arcpy.GetParameterAsText(0)
folderLocation = arcpy.GetParameterAsText(1) + '/'
# Check if feature class is shapefile or in a geodatabase
dataset = arcpy.Describe(fc).extension
from PIL import Image
left = 290
up = 1852
right = 357
bottom = 1915
image_list = [f for f in glob.glob("*.jpg")]
num = 0
"""
1. Install python 3.x from python.org
2. Install Python Imaging Library (PIL). Open CMD and type "pip install python3-imaging"
3. Install pytesseract. Open CMD and type "pip install pytesseract"
4. Install tesseract from https://github.com/UB-Mannheim/tesseract/wiki
5. Add tesseract install folder to path in windows
6. Add digits database from https://github.com/Shreeshrii/tessdata_shreetest to tesseract install folder !! NOT WORKING 100% !!
7. Do your own training http://pretius.com/how-to-prepare-training-files-for-tesseract-ocr-and-improve-characters-recognition/
8. Install ExifRead Open CMD and type "pip install exifread"
"""
{
"Framework":"Keras",
"InferenceFunction":"MaskRCNN.py",
"ModelConfiguration":"DeepLab",
"ModelFile":"mask_rcnn_coco.h5",
"ModelType":"ImageClassification",
"ExtractBands": [0,1,2,3],
"ImageWidth":256,
"ImageHeight":256,
@OterLabb
OterLabb / extent.py
Last active February 26, 2019 21:57
sc = arcpy.SearchCursor(selectFishnets)
# Create empty list for kmz names
kmzList = []
# Download for each feature in selected fishnets feature
for row in sc:
# Get extent for each feature
geom = row.shape
extents = []
# Converting kmz to raster
for kmz in kmzList:
arcpy.AddMessage("Converting {0} of {1} .kmz files".format(firstCount,count))
kmzFile = os.path.join(tempFolder, kmz + '.kmz')
arcpy.KMLToLayer_conversion(kmzFile, tempFolder, kmz, True)
firstCount += 1
# Enable adding data to map again and arcpy.AddMessage status
arcpy.env.addOutputsToMap = 1
arcpy.AddMessage("Creating raster mosaic dataset")