|
POST
|
With the right code formatting: #!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
#
import numpy as np
import arcpy
import pandas as pd
import sys, os
# Encoding der Standardausgabe herausfinden
stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()
arcpy.env.overwriteOutput = True
inTable = r"R:\Karto\Bierer2019\FFH_MEKA_FACT\Tabellen\wk13.xlsx"
outP = r"R:\Karto\Bierer2019\FFH_MEKA_FACT\Shape"
fc = r"\\RPKSF001\GIS_DATA\ArcUISTools15\Data\UIS_ALk.gdb\UIS_0100000047100001"
fl = "ALK"
# Tabelle
Flrstkz = pd.read_excel(inTable, index_col=None, na_values=['NA'], parse_cols = "A")
x = np.array(Flrstkz)
x1 = np.array(map(str, x))
x2 = x1.tolist()
field = 'FLURSTUECKSKENNZEICHEN'
sc = "'" + field + " IN ({})".format(x2) + "'"
sc1 = sc.replace("[", "")
sc2 = sc1.replace("]", "")
print sc2
arcpy.MakeFeatureLayer_management(fc, fl)
arcpy.SelectLayerByAttribute_management (fl, "NEW_SELECTION", sc2)
outFc = os.path.join(outP, "ALK_WK13.shp")
arcpy.CopyFeatures_management(fl, outFc)
... View more
04-02-2019
07:32 AM
|
0
|
0
|
2448
|
|
POST
|
I changed the code in this, but have problems to code the selection quercy properly. #!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
#
import numpy as np
import arcpy
import pandas as pd
import sys, os
# Encoding der Standardausgabe herausfinden
stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()
arcpy.env.overwriteOutput = True
inTable = r"R:\Karto\Bierer2019\FFH_MEKA_FACT\Tabellen\wk13.xlsx"
outP = r"R:\Karto\Bierer2019\FFH_MEKA_FACT\Shape"
fc = r"\\RPKSF001\GIS_DATA\ArcUISTools15\Data\UIS_ALk.gdb\UIS_0100000047100001"
fl = "ALK"
# Tabelle
Flrstkz = pd.read_excel(inTable, index_col=None, na_values=['NA'], parse_cols = "A")
x = np.array(Flrstkz)
x1 = np.array(map(str, x))
x2 = x1.tolist()
field = 'FLURSTUECKSKENNZEICHEN'
sc = "'" + field + " IN ({})".format(x2) + "'"
sc1 = sc.replace("[", "")
sc2 = sc1.replace("]", "")
print sc2
arcpy.MakeFeatureLayer_management(fc, fl)
arcpy.SelectLayerByAttribute_management (fl, "NEW_SELECTION", sc2)
outFc = os.path.join(outP, "ALK_WK13.shp")
arcpy.CopyFeatures_management(fl, outFc) Line 28 is somehow wrong. The print of sc2 looks like this: 'FLURSTUECKSKENNZEICHEN IN ('8334100002890000384', '8334100002890000384', '8334100002890000384', '8334100002890000384')' but gives a error in Line 37? Invalid expression?
... View more
04-02-2019
07:22 AM
|
0
|
3
|
2448
|
|
POST
|
I would like to use numpy array from a excel file for a selection of features. Do I have to convert the array to a list first, and how to do that? With the following code I get the following error? Or some better ideas, many files to select? #!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
#
import numpy as np
import arcpy
import pandas as pd
import sys, os
# Encoding der Standardausgabe herausfinden
stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()
inTable = r"R:\Karto\Bierer2019\FFH_MEKA_FACT\Tabellen\wk13.xlsx"
outP = r"R:\Karto\Bierer2019\FFH_MEKA_FACT\Shape"
fc = r"\\RPKSF001\GIS_DATA\ArcUISTools15\Data\UIS_ALk.gdb\UIS_0100000047100001"
fl = "ALK"
# Tabelle
Flrstkz = pd.read_excel(inTable, index_col=None, na_values=['NA'], parse_cols = "A")
x = np.array(Flrstkz)
arcpy.MakeFeatureLayer_management(fc, fl)
field = 'FLURSTUECKSKENNZEICHEN'
for i in x:
print i
sc = "%s = + %s"(field, i)
print sc
arcpy.SelectLayerByAttribute_management (fl, "NEW_SELECTION", sc)
outFc = os.path.join(outP, "WK13_"+ i + ".shp")
arcpy.CopyFeatures_management(fl, outFc) [8334100002890000384] Traceback (most recent call last): File "R:/Karto/zGIS/Python_2019/NumPy/NumPY_MEKA_FAKT.py", line 30, in <module> sc = "%s = + %s"(field, i) TypeError: 'str' object is not callable Better would be the "quercy" in (np.array)?
... View more
04-02-2019
05:06 AM
|
0
|
12
|
3702
|
|
POST
|
You could use the code of Rhett Zufelt and go one with writing every unique value to a list and use the max of the list to find the highest count. for val in Uni:
MyList.append(val)
MaxValue = max(MyList)
print "Max value element : ", MaxValue After that you can use MaxValue to do a select by attribute on your featureclass which I would copy before. Let you give out the name of the selected row with another search cursor for row in arcpy.SearchCursor(fc_Layer): print row.FILE_NAME Write this to a text file Delete the selected feature and go to the next MaxValue
... View more
03-28-2019
06:56 AM
|
2
|
1
|
3185
|
|
POST
|
If I do get it right, the name difference between the two raster to chose is name_01 and name_03 ? Maybe this script can help you? import arcpy, os
from arcpy.sa import *
arcpy.CheckOutExtension ("Spatial")
arcpy.env.overwriteOutput = True
# Paths to your rasterdata ?
arcpy.env.workspace = r'C:\pathToRaster1'
inws = arcpy.env.workspace
inws1 = r'C:\pathToRaster2'
outws = r'C:\outRaster'
# List all rasters
rasters = arcpy.ListRasters()
# 2) Loop through your raster list
for r in rasters:
prefix = os.path.splitext(r)[0]
suffix = os.path.splitext(r)[1]
prefix1 = prefix.rstrip("1")
raster2 = os.path.join(inws1, prefix1 + "3" + suffix)
print raster2
outraster = os.path.join(outws, prefix1 + "4" + ".tif") # Change the number
print outraster
# perform the raster algebra
mycalc = arcpy.sa.Raster(r) * arcpy.sa.Raster(raster2)
# Save to disk (write to .tif)
mycalc.save(outraster)
arcpy.CheckInExtension ("Spatial")
... View more
03-21-2019
05:13 AM
|
1
|
19
|
3731
|
|
POST
|
You have to decode the filename first to get it to run and write the filenames to the list.
... View more
03-20-2019
06:19 AM
|
0
|
0
|
583
|
|
POST
|
I get the following error with the this script because of the ß in filename: Weißstorch.shp. Any ideas how to solve this? Python 2.7.10 # -*- coding: utf-8 -*-
import os, time, xlwt
import xlrd
from xlrd import open_workbook
myPath = r"R:\Daten\geo_daten\Arten\2015_SIC\LUBW_Weissstorch_Horststandorte"
SHPCounter = 0
MyList = list()
Zusammengef = r"C:\temp_Geodatenverzeichnis\Nutzung.xls"
for path, dirs, files in os.walk(myPath):
for file in files:
if file.lower().endswith('.shp'):
print path + "\\" + file
SHPCounter += 1
print SHPCounter
accessTime = os.path.getatime(os.path.join(path, file)) # last access time
actualTime = time.time()
MyList.append(path + "\\" + file + "___" + file + "___" + ("""{}
""".format(int((actualTime - accessTime)/3600))))
# Write in excel
data = []
for line in MyList:
data.append([word for word in line.split("___") if word])
print data
wb = xlwt.Workbook()
sheet = wb.add_sheet("NichtGenutzt")
for row_index in range(len(data)):
for col_index in range(len(data[row_index])):
sheet.write(row_index, col_index, data[row_index][col_index])
wb.save(Zusammengef) Error Message and print statements: R:\Daten\geo_daten\Arten\2015_SIC\LUBW_Weissstorch_Horststandorte\LUBW_Weißstorch_Horststandorte_E.shp 1 [['R:\\Daten\\geo_daten\\Arten\\2015_SIC\\LUBW_Weissstorch_Horststandorte\\LUBW_Wei\xdfstorch_Horststandorte_E.shp', 'LUBW_Wei\xdfstorch_Horststandorte_E.shp', '1551\n ']] UnicodeDecodeError: 'ascii' codec can't decode byte 0xdf in position 74: ordinal not in range(128)
... View more
03-20-2019
05:00 AM
|
0
|
1
|
649
|
|
POST
|
It is possible to run intersect tool with only one input theme, is the result reliable the overlaps of this feature class?
... View more
03-14-2019
02:17 AM
|
0
|
0
|
433
|
|
POST
|
The input location is a folder with jpeg images and the raster dataset is created by the code.
... View more
12-04-2017
01:21 AM
|
0
|
1
|
958
|
|
POST
|
Hello, if I use the following python script to create a fgdb with a raster dataset this works, but the raster dataset remains empty. So the command arcpy.WorkspaceToRasterDataset_management doesn't do anything. There's no error message. import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
# Local variables:
RasterCatalog_gdb = arcpy.GetParameterAsText(0) # FileGDB
PfadFGDB = arcpy.GetParameterAsText(1) # Pfad FGDB
Dataset = arcpy.GetParameterAsText(2)# Raster Catalog
PfadWorkspace = arcpy.GetParameterAsText(3) # Workspace mit Bildern
RasterGdb = PfadFGDB + "/" + RasterCatalog_gdb + ".gdb"
arcpy.AddMessage(RasterGdb)
DatasetPfad = PfadFGDB + "/" + RasterCatalog_gdb + ".gdb" + "/" + Dataset
arcpy.AddMessage(DatasetPfad)
try:
# Process: File-Geodatabase erstellen
arcpy.CreateFileGDB_management(PfadFGDB, RasterCatalog_gdb, "CURRENT")
# Process: Raster-Dataset erstellen
arcpy.CreateRasterDataset_management(RasterGdb, Dataset, "0,2", "8_BIT_UNSIGNED", "PROJCS['DHDN_3_Degree_Gauss_Zone_3',GEOGCS['GCS_Deutsches_Hauptdreiecksnetz',DATUM['D_Deutsches_Hauptdreiecksnetz',SPHEROID['Bessel_1841',6377397.155,299.1528128]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',3500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',9.0],PARAMETER['Scale_Factor',1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]", "3", "", "PYRAMIDS -1 NEAREST LZ77 75 NO_SKIP", "128 128", "LZ77", "")
arcpy.env.pyramid = "PYRAMIDS 3 BILINEAR JPEG"
arcpy.env.rasterStatistics = "STATISTICS 4 6 (0)"
arcpy.BuildPyramidsAndStatistics_management(PfadWorkspace, "INCLUDE_SUBDIRECTORIES", "BUILD_PYRAMIDS", "CALCULATE_STATISTICS")
# Process: Workspace in Raster-Dataset
arcpy.WorkspaceToRasterDataset_management(PfadWorkspace, DatasetPfad, "NONE", "LAST", "MATCH", "", "", "NONE", "0", "HISTOGRAM_MATCHING", "NONE")
except:
print "failed"
print arcpy.GetMessages() Could it be that the dataset definition don't fit with the type of raster source files? Dataset: Raster Source file (jpeg): I don't find any differences. Or is it something with the calculation of statistics? If I use the toolbox tools to load the data manually into the dataset, there's as well no error message and there's afterwards the same empty dataset although the tool message ends with a sucessful loading of the data.
... View more
12-01-2017
12:38 AM
|
0
|
3
|
1297
|
|
POST
|
Is it possible to define case sensitive coded domain attribut values in one feature class in ArcGIS Desktop (10.2.2) for editing? For example I have species 1 with possible habitats A, B, C and species 2 with the possible habitats A, D, E. Or is this only possible if I use one feature class for each species?
... View more
11-20-2017
11:15 PM
|
0
|
2
|
1186
|
|
POST
|
Perfect thank you ! Only a very small thing - it's not arcpy.CopyFeatures_management(infileL, outFeature)
must be:
arcpy.CopyFeatures_management(infileL, fc_pathname ) I think?
... View more
11-08-2017
04:56 AM
|
1
|
1
|
2707
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-10-2025 08:08 AM | |
| 1 | 05-13-2025 05:05 AM | |
| 1 | 04-28-2025 03:40 AM | |
| 4 | 08-13-2024 10:49 PM | |
| 1 | 08-13-2024 09:52 PM |
| Online Status |
Offline
|
| Date Last Visited |
Monday
|