155GIS2 / 10. cvičení: Porovnání verzí
m (→ArcPy) |
|||
(Není zobrazeno 14 mezilehlých verzí od stejného uživatele.) | |||
Řádek 29: | Řádek 29: | ||
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> | ||
inputFC = arcpy.GetParameterAsText(0) | inputFC = arcpy.GetParameterAsText(0) | ||
shapeType = arcpy.Describe(inputFC).shapeType | shapeType = arcpy.Describe(inputFC).shapeType | ||
arcpy.AddMessage("Shape Type: {}".format(shapeType)) | arcpy.AddMessage("Shape Type: {}".format(shapeType)) | ||
</syntaxhighlight> | |||
; Geoprocessing | |||
* [https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/select.htm Select] | |||
* [https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/buffer.htm Buffer] | |||
<syntaxhighlight lang=python> | |||
arcpy.env.workspace = r"C:\users\martin\Documents\GIS2" | |||
# vyber a export dalnic | |||
silnice = r"C:\Users\martin\Documents\ArcCR500\ArcCR500_v33.gdb\Silnice_2015" | |||
dalnice = "dalnice.shp" | |||
arcpy.Select_analysis(silnice, dalnice, "TRIDA = 1") | |||
# buffer kolem dalnic | |||
buffer_dal = "dalnice_buf.shp" | |||
vzdalenost = "5000 meters" | |||
arcpy.Buffer_analysis(dalnice, buffer_dal, vzdalenost, dissolve_option="ALL") | |||
# odstraneni nepotrebnych vrstev | |||
arcpy.Delete_management(dalnice) | |||
</syntaxhighlight> | |||
; Rastrová data (numpy) | |||
* [https://numpy.org/ knihovna NumPy] | |||
* [https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/working-with-numpy-in-arcgis.htm Working with NumPy in ArcGIS] | |||
<syntaxhighlight lang=python> | |||
dmt = r"C:\Users\martin\Documents\ArcCR500\ArcCR500_v33.gdb\DigitalniModelReliefu" | |||
# otestovat nacteni dat | |||
data = arcpy.Describe(dmt) | |||
data.dataType | |||
# nacteni metadat rastru | |||
raster = arcpy.Raster(dmt) | |||
raster.width, raster.height | |||
# nacteni rastrovych hodnot do numpy pole | |||
array = arcpy.RasterToNumPyArray(raster) | |||
type(array) | |||
# rozmer a datovy typ pole | |||
array.shape, array.dtype | |||
# zjisteni minimalni, maximalni hodnoty | |||
array.min(), array.max() | |||
# cetnost hodnot | |||
unique, counts = numpy.unique(array, return_counts=True) | |||
idx = numpy.where(unique == 200) | |||
counts[idx] | |||
# ukazka mapove algebry | |||
array[(array>=0) & (array<=200)] = 0 | |||
array[(array>200)] = 1 | |||
array.min(), array.max() | |||
# zapis numpy pole do rastru | |||
vystup = arcpy.NumPyArrayToRaster(array) | |||
vystup.save(r"C:\users\martin\Documents\dmt200.tif") | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Řádek 40: | Řádek 101: | ||
=== ArcGIS === | === ArcGIS === | ||
* [https://developers.arcgis.com/python/guide/using-the-api/ ArcGIS API for Python] | |||
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> | ||
import arcgis | import arcgis | ||
gis = arcgis.GIS('home') | |||
user = gis.users.get('myusername') | |||
user | |||
### | |||
map1 = gis.map() | |||
map1 | |||
### | |||
map2 = gis.map(location='San Francisco, CA', zoomlevel = 12) | |||
map2 | |||
### | |||
from IPython.display import display | |||
gis | items = gis.content.search('Praha', item_type="Feature Layer", outside_org=True) | ||
print(len(items)) | |||
for item in items[:3]: | |||
display(item) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Verze z 21. 4. 2021, 15:31
Skriptování v ArcGIS Pro, pokročilé funkce Model Builder
Pokročilé funkce Model Builder
- Examples of inline model variable substitution
- Creating stand-alone variables
- Using Lists
- What is geoprocessing?
Skriptování v ArcGIS Pro
PyCharm
Postupujte podle návodu. Zvolte cestu k Python interpretu odkazující na ArcGIS: C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
Úlohy
V následujících úlohách budeme, pokud nebude uvedeno jinak, používat data z datové sady ArcCR500. Tato datová sada je poskytovaná firmou ArcData zdarma.
V učebně B-870 jdou data nainstalována v adresáři
S:\K155\Public\data\ArcGIS\ArcCR500 3.3
Přístupová práva k tomu adresáři jsou omezena pouze na čtení! Nelze tedy datové vrstvy z ArcCR500 upravovat (včetně např. vytváření pyramid).
ArcPy
- Výpis typu geoprvků - připojit jako skript
inputFC = arcpy.GetParameterAsText(0)
shapeType = arcpy.Describe(inputFC).shapeType
arcpy.AddMessage("Shape Type: {}".format(shapeType))
- Geoprocessing
arcpy.env.workspace = r"C:\users\martin\Documents\GIS2"
# vyber a export dalnic
silnice = r"C:\Users\martin\Documents\ArcCR500\ArcCR500_v33.gdb\Silnice_2015"
dalnice = "dalnice.shp"
arcpy.Select_analysis(silnice, dalnice, "TRIDA = 1")
# buffer kolem dalnic
buffer_dal = "dalnice_buf.shp"
vzdalenost = "5000 meters"
arcpy.Buffer_analysis(dalnice, buffer_dal, vzdalenost, dissolve_option="ALL")
# odstraneni nepotrebnych vrstev
arcpy.Delete_management(dalnice)
- Rastrová data (numpy)
dmt = r"C:\Users\martin\Documents\ArcCR500\ArcCR500_v33.gdb\DigitalniModelReliefu"
# otestovat nacteni dat
data = arcpy.Describe(dmt)
data.dataType
# nacteni metadat rastru
raster = arcpy.Raster(dmt)
raster.width, raster.height
# nacteni rastrovych hodnot do numpy pole
array = arcpy.RasterToNumPyArray(raster)
type(array)
# rozmer a datovy typ pole
array.shape, array.dtype
# zjisteni minimalni, maximalni hodnoty
array.min(), array.max()
# cetnost hodnot
unique, counts = numpy.unique(array, return_counts=True)
idx = numpy.where(unique == 200)
counts[idx]
# ukazka mapove algebry
array[(array>=0) & (array<=200)] = 0
array[(array>200)] = 1
array.min(), array.max()
# zapis numpy pole do rastru
vystup = arcpy.NumPyArrayToRaster(array)
vystup.save(r"C:\users\martin\Documents\dmt200.tif")
Další ukázky skriptů zde (zip).
ArcGIS
import arcgis
gis = arcgis.GIS('home')
user = gis.users.get('myusername')
user
###
map1 = gis.map()
map1
###
map2 = gis.map(location='San Francisco, CA', zoomlevel = 12)
map2
###
from IPython.display import display
items = gis.content.search('Praha', item_type="Feature Layer", outside_org=True)
print(len(items))
for item in items[:3]:
display(item)
Model
- proměnné
- Obce, Select, název obce
- list (není podporováno ArcGIS Pro)
- Silnice, Select, Buffer
- iterace
- Kraje, Iterate Feature Selection, Copy Features