@@ -29,60 +29,6 @@ those who do not have the time and/or interest in learning a new language.
29
29
By having the speed and scalability of Scala and the ease of Python,
30
30
GeoPySpark is then the remedy to this predicament.
31
31
32
- A Quick Example
33
- ----------------
34
-
35
- Here is a quick example of GeoPySpark. In the following code, we take NLCD data
36
- of the state of Pennsylvania from 2011, and do a masking operation on it with
37
- a Polygon that represents an area of interest. This masked layer is then saved.
38
-
39
- If you wish to follow along with this example, you will need to download the
40
- NLCD data and unzip it.. Running these two commands will complete these tasks
41
- for you:
42
-
43
- .. code :: console
44
-
45
- curl -o /tmp/NLCD2011_LC_Pennsylvannia.zip https://s3-us-west-2.amazonaws.com/prd-tnm/StagedProducts/NLCD/2011/landcover/states/NLCD2011_LC_Pennsylvania.zip?ORIG=513_SBDDG
46
- unzip -d /tmp /tmp/NLCD2011_LC_Pennsylvannia.zip
47
-
48
- .. code :: python
49
-
50
- import geopyspark as gps
51
-
52
- from pyspark import SparkContext
53
- from shapely.geometry import box
54
-
55
-
56
- # Create the SparkContext
57
- conf = gps.geopyspark_conf(appName = " geopyspark-example" , master = " local[*]" )
58
- sc = SparkContext(conf = conf)
59
-
60
- # Read in the NLCD tif that has been saved locally.
61
- # This tif represents the state of Pennsylvania.
62
- raster_layer = gps.geotiff.get(layer_type = gps.LayerType.SPATIAL ,
63
- uri = ' /tmp/NLCD2011_LC_Pennsylvania.tif' ,
64
- num_partitions = 100 )
65
-
66
- # Tile the rasters within the layer and reproject them to Web Mercator.
67
- tiled_layer = raster_layer.tile_to_layout(layout = gps.GlobalLayout(), target_crs = 3857 )
68
-
69
- # Creates a Polygon that covers roughly the north-west section of Philadelphia.
70
- # This is the region that will be masked.
71
- area_of_interest = box(- 75.229225 , 40.003686 , - 75.107345 , 40.084375 )
72
-
73
- # Mask the tiles within the layer with the area of interest
74
- masked = tiled_layer.mask(geometries = area_of_interest)
75
-
76
- # We will now pyramid the masked TiledRasterLayer so that we can use it in a TMS server later.
77
- pyramided_mask = masked.pyramid()
78
-
79
- # Save each layer of the pyramid locally so that it can be accessed at a later time.
80
- for pyramid in pyramided_mask.levels.values():
81
- gps.write(uri = ' file:///tmp/pa-nlcd-2011' ,
82
- layer_name = ' north-west-philly' ,
83
- tiled_raster_layer = pyramid)
84
-
85
-
86
32
Contact and Support
87
33
--------------------
88
34
0 commit comments