Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Draw a map of a country for a land bus transport network

    Dear Stata users, Hello;

    I'am currently working on the transport network of a public bus company that's providing interurban services for the country.
    I do would love to generate a map of the network with the help of the spmap command and the shapefile of the country, in a way that the result is a map of this company's network.

    First of all, is it possible to use the spmap map command and the shapefile for that matter?
    Second, what kind of data should I collect from this transport firm in order to draw the map?

    I would appreciate it if I could get some help. Thanks!

  • #2
    Hey Aziz,

    as far as I can tell from your description spmap is exactly the command you would want to use. In addition to the shapefile of the country that you already mentioned, you need a second shapefile that includes the network (likely lines connecting cities). You can also use a third shapefile that has points for the bus-stops (that are connected by the lines in the other shapefile).

    The workflow in Stata:

    1) Transform your shapefiles to .dta files using shp2dta from ssc.
    2) Use spmap to plot the .dta file of the country and use the suboption line() to overlay the network and points() to overlay the bus-stops.
    3) Fine-tune the optics of your map

    Best,
    Sebastian

    Comment


    • #3
      Dear Sebastian Schirner Hello and Thanks for the clarification;

      I was wondering if the spmap is the correct command for this kind of job, I'am used to that command but only in showing regional and spacial socio-economic indexes, but, will it be the best option for a good clear quality representation for a transportation firm's network? Because I'm just suspecting that Stata could have a more specialized command for that kind of job.
      As for the Shapefiles, the Shapefile of the ountry I'm working on, Tunisia, is well available, as well as the third one of the bus-stops (i do have the name of each bus stop, with an id number, and the latitude and the longitude position for each stop), but I don't havethe second Shapefile that you've mentionned: The network with lines connecting cities, so I don't know if I could work with only the two that I've just mentionned.

      Again, Thanks for the help Sebastian Schirner
      ​​​​​​​

      Comment


      • #4
        Hey Aziz,

        I am sorry that I misunderstood you and that I was implying that you do not know spmap. You can create the second shapefile within Stata. As you have the coordinates of the bus-stops (and the routes that connect them) you could define the lines yourself accordingly. The following is not a completly reproducable example, but if you use your shapefile and adjust the _ID you should be able to make it work. The key is that the start- and end coordinates of your lines need to be seperated by a missing value for _X and _Y.

        Code:
        * First get .dta files (in this case of Germany)
        shp2dta using "Census\VG250_Gemeinden.shp", database("database.dta") coordinates("coordinates.dta") replace
        
        * Get (arbitrary) coordinates of two points (you already have that)
        use "coordinates.dta", clear
        keep if _ID == 10097 | _ID == 6525
        bysort _ID: egen centroid_X = mean(_X)
        bysort _ID: egen centroid_Y = mean(_Y)
        bysort _ID: keep if _n == 1
        drop _X _Y
        rename centroid_X _X
        rename centroid_Y _Y
        
        * Now there has to be a missing value for _X and _Y to distinguish the features. The order of missing and non missing values is important! You can add further lines accordingly.
        set obs  3
        replace _ID = 10097 if _n == 3
        replace _ID=_ID[1]
        gsort -_X, mfirst
        save "cities_line_test.dta", replace
        
        use "database.dta", clear
        g indicator = 1
        spmap indicator using "coordinates.dta", id(_ID) fcolor( gs12 ) line(data(cities_line_test.dta") color(red))
        Best,
        Sebastian

        Comment


        • #5
          Sebastian Schirner Dear Sebastian, Hello again;

          It is ok Sir, I wasn't also implying that you thought that way And thanks very much for the help and the consideration of my questions.

          I don't get what do you mean by "the routes that connect them", since the origin-destination could be connected by one or lots of roads (depending on the roads network of the country), but also, here I want to draw only the network that the enterprise I'm working in is actually using, because sureley it is not using all of the roads of the country, but yet, for some transport lines cases, it could be using more than one road for getting from an origin to a destination.

          Another thing to ask: Should I get a simple Shapefile of the country I'm working on, that is Tunisia, or should I look for a Shapefile which has the road network with it? I don't want to represent all of the roads of the country in the final graph, but just the ones that the enterprise is using, yet I don't know if I should get an advanced Shapefile ofr just a simple one presenting just the governorates and the cities of the country.

          It would be helpful to me if I could get more on that.

          Best regards;
          Aziz

          Comment


          • #6
            Hey Aziz,

            regarding the first part. I was thinking about straight lines connecting the stops. The underlying road network makes more sense in your case. I think you would need a shapefile with the exact routes, because coding them manually in Stata would be very cumbersome.

            Regarding the second part: I suggest you use a plain shapefile of the country to get the foundation for the map. Then you go to OpenStreetMap where you can get free shapefiles with (among others) the road network of virtually all countries in the world. Then you transform the OpenStreetMap shapefile to .dta and determine which roads are taken by the company (that may involve some cumbersome manual work depending on the number of routes). Drop all the other roads from your .dta file and then create the map.

            Best,
            Sebastian

            Comment


            • #7
              Hello Sebastian Schirner ;

              For the first point: I don't believe that I need to show all the roads of the country in the final map graph that I would love to have, because it will be too crowded for a map graph. Also, my goal is not to study all the roads of the country, but just the ones that the transport enterprise is using for its bus operations. Yet, I'll see about that.

              For the second point: I already don't know is there are Shapefiles with the roads coordinates available for my country already, still looking and I couldn't find one that's good to work with. As for the idea of the OpenStreetMap, I don't know what that is actually, I have to discover it myself and know how to exploit the road Shapefile that I could get from it.

              Anyway, certainly there will be a continuity to this discussion with you dear Sebastian Schirner.

              ​​​​​​​ Thanks for the help!

              Comment


              • #8
                Sebastian Schirner Hello Again;

                I did upload a full on Zip folder cpg, dbf, prj, shp and shx for Tunisia, those folders do have the Goefabrik type, I've never worked with such data.
                I do have some files called "gis_osm_building" and "gis_osm_waterways" and "gis_osm_roads" and all of that, I guess there are 6 or 7 types of files.
                I guess then I'm going to have to use the "gis_oms_roads", the "gis_oms_traffic" and the "gis_oms_transport" files, but that would get me the whole transport and road network for the whole country.

                This is my first time working on such data and wanting to draw the kind of map, I guess it is a bit ambitious!

                I would love to get some more help if you don't mind.

                With many thanks!

                Comment


                • #9
                  Hey Aziz,

                  you are right, you would want to use the file "gis_oms_roads.shp". Then you can proceed in principle as described above:

                  "Regarding the second part: I suggest you use a plain shapefile of the country to get the foundation for the map. Then you go to OpenStreetMap where you can get free shapefiles with (among others) the road network of virtually all countries in the world. Then you transform the OpenStreetMap shapefile to .dta and determine which roads are taken by the company (that may involve some cumbersome manual work depending on the number of routes). Drop all the other roads from your .dta file and then create the map."

                  Without knowledge about the routes and the exact data that you use it is hard to tell more.

                  Best,
                  Sebastian

                  Comment

                  Working...
                  X