filmov
tv
Using Python in GIS: Text file to DBF

Показать описание
First video in series in automating processes in GIS. This is not a Python tutorial per se, but rather an example of how to use Python in automating processes. In this example we are converting a text file into a DBF for further processing of Landsat scenes.
Twitter: @my_physical
Instagram: @MyPhysicalWorld
code used for this video: (I am not a programmer so this code might seem goofy to "real" programmers)
import os
import arcpy
from operator import itemgetter
# ------------------------------------Set path to the folder: (replace with your own filepath!):
#Print("Enter Directory:")
folder = r"D:\GISProgramming"
outFolder = r"D:\GISProgramming"
dbFolder = r"D:\GISData\Landsat"
# -------------------------------------------Set name of the file
# --------------------------------------Generate full filepath by combining the folder and filename
# ----------------------------------------------------Delete unneeded lines from MetaData file
with open(fileName) as old, open(newFile, 'w') as new:
# ---------------------------------------------------- Create clean Meta file and Database
of = open(op, "w")
arcpy.DeleteRows_management(OurTable)
with open(fp, "r") as infile:
Field = [] # -------------------------------------Creates Field List
Value = [] # -------------------------------------Creates Value List
Band = []
Type = []
Class = []
# -----------------------------------------------------Begin File Work
for line in infile:
if nline == "": # ---------------------------Test for End of File
print("Reached End of File")
break
else:
# print (nline)
fld = splitLine[0]
type = splitField[1]
cls = splitField[0]
bnd = splitField[3]
print(bnd)
# print(fld)
val = splitLine[1]
nval = "{:.7f}".format(float(val)) # -------Convert Scientific Notation to Decimal
# print(val)
# print(nval)
#print(splitLine)
row = [fld, bnd, nval, type, cls]
del editrows
Twitter: @my_physical
Instagram: @MyPhysicalWorld
code used for this video: (I am not a programmer so this code might seem goofy to "real" programmers)
import os
import arcpy
from operator import itemgetter
# ------------------------------------Set path to the folder: (replace with your own filepath!):
#Print("Enter Directory:")
folder = r"D:\GISProgramming"
outFolder = r"D:\GISProgramming"
dbFolder = r"D:\GISData\Landsat"
# -------------------------------------------Set name of the file
# --------------------------------------Generate full filepath by combining the folder and filename
# ----------------------------------------------------Delete unneeded lines from MetaData file
with open(fileName) as old, open(newFile, 'w') as new:
# ---------------------------------------------------- Create clean Meta file and Database
of = open(op, "w")
arcpy.DeleteRows_management(OurTable)
with open(fp, "r") as infile:
Field = [] # -------------------------------------Creates Field List
Value = [] # -------------------------------------Creates Value List
Band = []
Type = []
Class = []
# -----------------------------------------------------Begin File Work
for line in infile:
if nline == "": # ---------------------------Test for End of File
print("Reached End of File")
break
else:
# print (nline)
fld = splitLine[0]
type = splitField[1]
cls = splitField[0]
bnd = splitField[3]
print(bnd)
# print(fld)
val = splitLine[1]
nval = "{:.7f}".format(float(val)) # -------Convert Scientific Notation to Decimal
# print(val)
# print(nval)
#print(splitLine)
row = [fld, bnd, nval, type, cls]
del editrows
Комментарии