Exercise 5: Working with vector dataYou will need to download this data and unzip it to your folder to use it for this exercise.Open and read the shapefile with OGR following the process we did in class. When using DumpReadable() method on a feature to print the feature into human readable format, Jupyter notebook doesnt show any output. This could be a problem with Jupyter notebook, or simply with the OGR python binding. So to work around this problem, you can try to run that piece of code within interactive python or python interpreter to get the list of attributes. Here is how to do it.Open a Linux terminal on the server by clicking on the terminal iconIn the terminal, enter module load geo429 to set up the proper environment. Then enter python command to start the python interpreter. See the following example. Notice that you have to use Python 3.5.2 with Anaconda for ogr to work. Other versions might/might not work. Once you load the geo429 module, the python environment should be for 3.5.2.lluo@black:~$ module load geo429lluo@black:~$ pythonPython 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linuxType help, copyright, credits or license for more information.>>>Copy and paste your code into the Python interpreter to run the following code. It should now give you the output from DumpReadable method. The output gives you the attributes that are associated with this specific feature. In this shapefile, all geographic features are counties of Michigan, and each county has the same attributes. The actual values associated with these attributes will obviously vary. But this will give you an idea what attributes that you can extract and work with.>>>from osgeo import ogr>>>shpf = ogr.Open(data/mich_co.shp)>>>lyr = shpf.GetLayer(0)>>>feature = lyr.GetFeature(0)>>>feature.DumpReadable()OGRFeature(mich_co):0FID (Integer64) = 0w_M_201 (Real) = 5312.000000000000000w_F_201 (Real) = 5176.000000000000000b_M_201 (Real) = 19.000000000000000b_F_201 (Real) = 27.000000000000000nA_M_20 (Real) = 35.000000000000000nA_F_20 (Real) = 41.000000000000000a_M_201 (Real) = 6.000000000000000a_F_201 (Real) = 19.000000000000000pop (Real) = 10635.000000000000000county (String) = Alconamarrigs (Real) = 51.000000000000000divorcs (Real) = 33.000000000000000POLYGON ((666667.467185152 480494.211763146,675142.281752073 480722.470884362,685792.431459327 481271.563931039,695290.517929201 481624.721626855,700062.989810847 481708.114326595,711456.115569082 482017.18594244,712100.355392683 480175.300987687,712974.328711306 479313.654057265,713359.156832663 477393.313839829,713885.474683868 476280.555491611,713672.894405104 474153.762459305,714188.458937549 471938.117692383,713694.791413845 470778.576325394,714144.89279161 468268.735545871,714774.799969475 467109.256103982,715988.963850573 466031.816244756,715674.904884499 463662.457350373,715212.114455894 461990.948710321,714620.334722815 458860.375639736,713424.491203851 456713.114505301,712899.162809242 454179.933320121,712873.64431283 452788.40893671,713210.606329985 448872.571019732,713693.291200278 446788.451035371,712947.017607005 443503.338960932,701836.417659922 443150.665716232,686638.68076447 442621.728127439,667811.141751631 441884.748812394,667480.119826987 453075.083321341,667076.870736058 464363.345038424,666841.937585521 475610.600646161,666667.467185152 480494.211763146))To exit from the Python interpreter, simply press Ctrl + d on the keyboard to exit. You can close the terminal once you have found out the above information.Now you should have the information you need to work with the shapefile, i.e, attribute names.Write code to find out the following using OGR:How many features are stored in this shapefile?In [1]:# your code herePrint out all the county name of each feature, the type of geometry for this county (i.e, point, line, polygon or multipolygon?) If you cannot do this with OGR, can you do it with Fiona?In [2]:# your code hereWrite code to find the number of marriages and divorces in Ingham county.In [3]:# your code hereWrite code to find the county with the highest population.In [4]:# your code hereIn [5]:# close the fileWorking with FionaUsing the Fiona module, open the mi_airports.shp file (download here), and write code to find out the following.How many features are stored in this shapefile and what geometry type are they?In [6]:# Your code hereHow many airports are in Ingham county?In [7]:# Your code hereWhich airport has the highest elevation?In [8]:# Your code hereImproving matplotlib plottingUse the functions that we developed in class, namely, getLineSegmentsFromGeometry, readShape, drawMultiPoints, drawMultiLines, drawMultiPolygons to work on this problem.Place all the functions (plotting and reading shapefiles with ogr) in a separate python file, called mymodule.py and save this mymodule.py in your current work directory. Congratulations! You just created your first module. You can also add DocString for your module to describe it. Your module will become very handy when we use these functions in the following questions. To use the function in your module, simply import themfrom mymodule import *Download this shapefile and unzip it. Import mymodule to read the shapefile. Make a plot of all the features in this shapefile using the functions in your module.In [11]:#your code and plot hereRevise the plotting functions in your module, to allow users to specify the colors when drawing. Place your new plotting functions here, and replot the polygons in the nybb.shp shapefile.In [10]:# Your code and plots here本团队核心人员组成主要包括BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 微信:codehelp QQ:99515681 或邮箱:99515681@qq.com 微信:codehelp
网友评论