Python Geospatial Analysis Cookbook by Unknown
Author:Unknown
Language: eng
Format: epub
Publisher: Packt Publishing
How it works...
A quick high-level run-through of what is going on here at the beginning should help clear the air. We have four functions and nine variables within our Python code to split the load of input and output data. The running of our code takes place in the if __name__ == "main": call that is found at the end of the code. We start defining two variables to deal with our inputs that we are going to union together. These two are our input Shapefiles and the other three outputs are GeoJSON and JavaScript files.
The create_shapes()function converts our Shapefile into Shapely MultiPolygon geometry objects. Inside the Python class, the list comprehension is used to generate a new list of polygon objects, which are the input list of polygons used to create our output MultiPolygon. Next, we'll simply run this function passing in our input Shapefiles.
Our create_union() function is up next where we do the real union work. We begin by unioning the two geometry boundaries together that produces a union set of LineStrings and represents the outer bounds of our input polygons. The reason for this is that we do not want to lose the geometries of both polygons, which will, by default, dissolve into one big polygon when simply passed into the Shapely union function. Therefore, we need to rebuild the polygons with the polygonize() Shapely function.
The polygonize function creates a Python generator object, not a simple geometry. This is an iterator that's similar to a list that we need to loop over to get at the individual polygons it's created for us.
We do exactly this in the next code segment using the enumerate() Python function that automatically creates an ID for us for each feature that we use as the id field in the attribute results. After our loop, we use the standard Python json.dump() method to export our newly created GeoJSON file and write it to disk using the Python open() method in the write mode.
Lastly, in our create_union() function, we prepare to output our resulting union polygon as a Shapely MultiPolygon object. This is accomplished simply by looping through the polygonize() iterator and outputting a list that feeds into the Shapely MultiPolygon()function. Finally, we execute the union function, passing in our two input geometries and specifying the output GeoJSON file.
So, we can view our results in our web map as we did in the previous exercise using a small function called write_wkt(). This little function takes the file path to the output JavaScript file that we want to create and the MultiPolygon result's geometry. Shapely then dumps the geometry into the Well Known Text format as we write it out to the JavaScript file.
In the end, a small function called output_geojson_fc() is used to output another GeoJSON file, this time using the Python geojson library. This simply shows you another way to recreate a GeoJSON file. Since GeoJSON is a plain text file, it is possible to create it in many unique ways depending on your personal programming preference.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Eco-friendly approach of bio-indigo synthesis and developing purification methods towards isolation of indigo from indirubin and bacterial fragments by Ramalingam Manivannan & Kaliyan Prabakaran & Young-A Son(149198)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74269)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(66072)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(65822)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(65257)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50857)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(32817)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(32734)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(32490)
What's Done in Darkness by Kayla Perrin(27102)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26482)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26435)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(21011)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20773)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20647)
The Fifty Shades Trilogy & Grey by E L James(19604)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19486)
Shot Through the Heart by Mercy Celeste(19345)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17490)