-
Notifications
You must be signed in to change notification settings - Fork 0
/
raster_to_polygon.py
65 lines (50 loc) · 3.36 KB
/
raster_to_polygon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2021-10-03 23:07:20
"""
import arcpy
def Model(): # Model
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
# Check out any necessary licenses.
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("spatial")
arcpy.CheckOutExtension("ImageAnalyst")
power_3_0_nn_50_0_tif = arcpy.Raster("power_3_0_nn_50.0.tif")
wisc_boundary_shp = "C:\\Users\\brianstrock\\PycharmProjects\\nitrate_cancer_dashboard\\shp\\wisc_boundary.shp"
# Process: Aggregate (Aggregate) (sa)
Aggrega_powe1 = "\\\\Mac\\Home\\Documents\\ArcGIS\\Projects\\MyProject15\\MyProject15.gdb\\Aggrega_powe1"
Aggregate = Aggrega_powe1
Aggrega_powe1 = arcpy.sa.Aggregate(in_raster=power_3_0_nn_50_0_tif,
cell_factor=2,
aggregation_type="MEAN",
extent_handling="EXPAND",
ignore_nodata="DATA")
Aggrega_powe1.save(Aggregate)
# Process: Int (Int) (sa)
Output_raster = "\\\\Mac\\Home\\Documents\\ArcGIS\\Projects\\MyProject15\\MyProject15.gdb\\Int_Aggrega_1"
Int = Output_raster
Output_raster = arcpy.sa.Int(in_raster_or_constant=Aggrega_powe1)
Output_raster.save(Int)
# Process: Majority Filter (Majority Filter) (sa)
Output_raster_2_ = "\\\\Mac\\Home\\Documents\\ArcGIS\\Projects\\MyProject15\\MyProject15.gdb\\Majorit_Int_1"
Majority_Filter = Output_raster_2_
Output_raster_2_ = arcpy.sa.MajorityFilter(in_raster=Output_raster, number_neighbors="FOUR", majority_definition="MAJORITY")
Output_raster_2_.save(Majority_Filter)
# Process: Region Group (Region Group) (sa)
Output_raster_3_ = "\\\\Mac\\Home\\Documents\\ArcGIS\\Projects\\MyProject15\\MyProject15.gdb\\RegionG_Majo1"
Region_Group = Output_raster_3_
Output_raster_3_ = arcpy.sa.RegionGroup(in_raster=Output_raster_2_, number_neighbors="FOUR", zone_connectivity="WITHIN", add_link="ADD_LINK", excluded_value=None)
Output_raster_3_.save(Region_Group)
# Process: Raster to Polygon (Raster to Polygon) (conversion)
RasterT_RegionG1 = "\\\\Mac\\Home\\Documents\\ArcGIS\\Projects\\MyProject15\\MyProject15.gdb\\RasterT_RegionG1"
with arcpy.EnvManager(outputMFlag="Disabled", outputZFlag="Disabled"):
arcpy.conversion.RasterToPolygon(in_raster=Output_raster_3_, out_polygon_features=RasterT_RegionG1, simplify="SIMPLIFY", raster_field="LINK", create_multipart_features="SINGLE_OUTER_PART", max_vertices_per_feature=None)
# Process: Smooth Polygon (Smooth Polygon) (cartography)
RasterT_RegionG1_SmoothPolyg = "\\\\Mac\\Home\\Documents\\ArcGIS\\Projects\\MyProject15\\MyProject15.gdb\\RasterT_RegionG1_SmoothPolyg"
with arcpy.EnvManager(transferGDBAttributeProperties=False):
arcpy.cartography.SmoothPolygon(in_features=RasterT_RegionG1, out_feature_class=RasterT_RegionG1_SmoothPolyg, algorithm="PAEK", tolerance="500 Miles", endpoint_option="FIXED_ENDPOINT", error_option="RESOLVE_ERRORS", in_barriers=[wisc_boundary_shp])
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace=r"\\Mac\Home\Documents\ArcGIS\Projects\MyProject15\MyProject15.gdb", workspace=r"\\Mac\Home\Documents\ArcGIS\Projects\MyProject15\MyProject15.gdb"):
Model()