How to Convert Coordinates from CSV to ESRI Shapefile

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to another tutorial now in this tutorial I'm going to show you how you can create a point shapefile from a data list like this now as an example I have selected a set of data which shows you the airports in the world now here you can see in the first column it shows you the country and the second and third columns show you the let the longitude and the latitude information correspondingly so I'm going to show you how we can transfer this data into an actual point ESRI shapefile using Python geo pandas so let's get started so first I'm going to go to this File Explorer and you can see over here I have this world Airport CSV file over here let me create a Python module CSV - point shapefile not py so first what you would need to do is you have to read in this sheet this CSV file you can read in CSV files easily you're sitting the pandas library so I'm going to import the pandas library first import pandas SPD and then I'm going to define one variable called airport data that's going to be equal to PD dot read CSV now since I keep my dot py file and the CSV file in the same location I can just simply specify world airport's dot CSV over here if not you will have to provide the full path alright now we can just go ahead and hit enter and now we can have a quick look Airport data dot head maybe let's have a look at the first 15 entries alright you can see that we have three columns country the longitude and the latitude now even if you go to the variables Explorer you can actually get get a much better weave you can see that all the data is here now still if you if you check the type of this data the name of the variable is Airport data you will see that the data type is actually pandas dataframe now we want to convert this from being a panda's data frame into a geo panda's geo data frame that means right now this variable does not have any geometrical properties even though it contains these two columns lonely longitude Atlit and latitude but right now the variable knows only that it has two columns but it has no idea especially where these where each of these points should actually be placed so get around that what we do is we convert this panda's data frame into geo pandas geo data frame so that it'll actually be spatially accurate as well all right so before going into that part just have a quick look at this this structure of of a geo pandas geo data frame now you can see that we have regularly similar to pandas data frames we have the index column and then we have a couple of columns like column 1 column 2 column 3 and so on but how this geo pandas geo data frame differs from a panda's data frame is through this special geometric column now this special geometry column is actually the reason why this geo pandas geo data frame differs from a regular pandas dataframe because now it has geometrical property as well so as you can see over here this is one example of a property that you would see in a geometric column as you can see over here it shows you point and some numbers inside now it doesn't necessarily need to be points it could either be polygons or it could be even something else so based on those given coordinate information inside each point entry the geo pandas dataframe knows exactly where to place each attribute especially with the correct geometrical accuracy for it so let's see how we can convert this pandas dataframe actually to look something like that geo pandas dataframe so in order to do that first you have to import the geo pandas library I'm going to import it as GPD alright now I'm going to create another variable called let's say Airport gdf which basically stands for Geo data frame and now I'm going to call this library GPD dot geo data frame because now we are going to create a new jade geo data frame based on the airport data over here and now very specifically we have to provide the corresponding entries for the geometry column so we pass one argument a special argument called geometry and that's going to be equal to GPD points from ex-wife all right now what we have to basically do is just provide the list of longitude and latitude beliefs now for example you can access the longitude beliefs over here by simply specifying the column name for example if you need to know the longitude beliefs you can do like this and it'll show the longitude values so I am going to specify this set over here as the longitude and then similarly you have to specify the set of latitude values as well I'm going to change this as latitude so basically this longitude is referring to this one and this latitude is referring to this one all right so that's pretty much it now if I run this command you will see that we did not get any error or anything like that and now if I try to see how this this Airport gdf looks now you can see that in addition to having this country longitude and latitude column it has actually created its own special geometry column which has assigned each and every entry each and every attribute its own geometrical properties now over here it has recognized that this is a point entry and over here it has specified the corresponding longitude and the latitude value now if you check the type of this we can check the type like this you can now see that it's actually a geo pendous geo data frame so now you can just have a quick look at the data just by saying gdf dot plot and you can see that we see the points over here but since the points are not very clear we can make a couple of adjustments we can reduce the marker size maybe to about 1.5 and also I can increase the figure size let's say 10 by 10 all right now let's run this one and see all right now you can see that we managed to successfully create a plot out of this CSV data that we had isn't it so each entry actually refers to one one point over here in this map now also let's see how let's learn how to save this file into into into an s3 shapefile so let me just go ahead and come in a couple of things out using pandas this one is creating a geo pandas your data frame using the pandas dataframe now finally we would like to save this as as in let's say s free shapefile all right now you what you can do is you can just say airports dot G d/f to file and over here you can specify the file name file name let's say I would say that mmm just I would say airports dot SHP because dot SHP is the extension of the shapefile but from that I also have to specify the driver argument which is ESRI shapefile now if you go ahead and run this now here you can see that we already have the airport's shapefile created however I see one issue now obviously over here you can see that we have a couple of files but as you might know when we create a shape file there should be a set of files including a projection file usually the extension of the projection file is dot prj but over here I do not see the projection file now the issue issue with that is let's say if you're using a GIS software like QGIS now just to open this if I just drag this and drop it over here you will see that the CRS was undefined the coordinate reference system was undefined because right now this cannot recognize what its coordinate system is because when we created the shapefile over here using geo pandas it somehow did not create the dot prj file so it is important to create the prj file so now I'm going to show you how we can actually export the shapefile in a way that it also creates the dot prj file so actually you can use that file for some useful purpose so what you need to do is first again have a look at this our geometric column now what I can do is I can just go to the variables explorer and now I can directly go to this Airport gdf now we're here you can see that my latitude and longitude believes it actually appears to be in decimal decrease so these points are basically in WGS 1984 geographical coordinate system in order to include the prj file you need to know something called the wkt information of that particular coordinate system wkt basically stands for well non-text so you need to know that well-known text code in order to export this shapefile including its correct projection so one way that you can do is actually you can first go to this website epsg dot io all right over here you can get the information about specific coordinate systems based on its epsg code now the epsg code for WGS 1984 geographic coordinate system is 43:26 so i'm just going to search based on that alright now if you scroll down over here you can see that the well-known text for s 3 is basically this particular code so this is actually what we need to extract from here now you can either copy this and paste it or you can just simply hit over here copy the text and create a variable called s 3w K T and I'm going to paste this as a string like this just make sure that you put this inside the codes alright now we have the s 3w Katie the well-known text now if you need to know the history w KD for another coordinate system basically what you need to do is you need to identify which epsg code that coordinate system refers to and come to the corresponding page just scroll down and from here you can get what the corresponding wkt code over here alright so since you have done that is 3 wget alright now what you have to do is just simply pass another argument called c RS wkt and that's going to be basically equal to this string all right all right now if I open back the folder you can see that we don't have any prj file over here and now if I run this command and if I open it back you will see that we have the dot prj file over here which basically contains all the projection information corresponding to this particular shapefile if I open that you can see that that wkt code has actually been transferred into this prj file now if I just go ahead and open so let me get rid of this one and now if I just go ahead and drag this one and drop it over here you see that it immediately recognizes what sort of a projection system it has and just right here you can see that it has already recognized the corresponding epsg and this way we did not get any errors or warnings or anything like that because now it actually has the the proper projection properties as well so if you want to add a base map maybe just to have a quick look you can even see that and maybe let me go ahead and reduce the size of the marker now you can see that everything works well these individual points actually referring to the to the airports so that's how you basically do a proper transfer of this kind of list of information with coordinates and convert it actually to a do a proper shapefile using using Python geo pandas all right I guess you enjoyed this tutorial if you did like it don't forget to click like and hit subscribe as well so thanks a lot for watching guys take care
Info
Channel: GeoDelta Labs
Views: 7,522
Rating: undefined out of 5
Keywords: geopandas, pandas, gis, geospatial, arcGIS, QGIS, processing, python, overlay, intersect, shapefile, Json, matplotlib, pyplot, geographical data, ESRI, Shapefile, how to, from CSV to Shapefile, Excel to Shapefile
Id: aVkdWSqKG_c
Channel Id: undefined
Length: 14min 3sec (843 seconds)
Published: Fri Apr 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.