How can I extract location hierarchy from Openstreetmap? - mysql

I need to store first parent of any Location entity in a mySQL database. So at the end I'll have a complete hierarchy. For example I need to know Berlin is part of Germany and store Germany as first parent of Berlin in the table. How can I query OSM for such information?

You can't query OSM directly for this information. Of course OSM contains such information, mainly through boundary relations and admin_levels. But the exact hierarchy between different elements has to be calculated first.
Geocoders for OSM can be used to obtain these information. The currently most popular one is Nominatim. You can install your own Nominatim instace by either importing the whole planet or an country or area extract. Then you can try to obtain these information via the database created by Nominatim.

Related

Splitting assets: Options for managing asset IDs and related records

I have road assets in a GIS layer (spatial table in an Oracle geodatabase).
Roads are split into separate lines/records where they intersect. This is an established business rule that cannot be changed.
Each road has work order records in a related table (in Maximo 7.6.1.1) that pertain to a point along the road.
Scenario:
A new road (#200) has been built that intersects an existing road (#100). Road #100 needs to be split into two separate roads at the intersection of road #200 (this is accomplished using GIS editing tools).
Question:
What are the options for managing the the road IDs and the related work order records?
Here are the options that I can think of:
Option 1:
Decommission the current road (#100) using the status field and create two new roads (#101 and #102).
The work order history will remain associated with the decommissioned road, not the new roads.
The road ID of the decommissioned asset could be stored in a decom_road_id field in the new roads.
Option 2:
Split the current road (#100). Keep the existing road_id for the section on the left-hand side (#100) and create a new road ID for the section on the right-hand side (#101).
The work order history will remain associated with the existing road (#100).
This means that the work order records on the right-hand side of the road will have incorrect road_ids.
Option 3:
Same as option 2, except we correct the road_id of the work orders on the right-hand side (to #101).

SQL Database Ride Sharing

I am designing a database for a ride sharing company(like Uber), it is from my home work actually. I have three tables - Driver,Customer and Ride, the customer and the driver have location attribute(latitude and longitude) which I represend them using double type. So my question is, can I make in SQL some arithmethic equation in order to the customer will get the closest car (using the location attributes) and in which table will be suit best the closest driver attribute in Customer or Ride?
Keep track of the location of the cars and as well to the customers, check in google how you can keep track of a location, which geographical attributes you need.
For the first question, I'm not sure but here are some informations.
http://fr.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
http://www.plumislandmedia.net/mysql/haversine-mysql-nearest-loc/
And for the second, I think you don't have to store the closest driver attribute.

database design for this road map

I am thinking about the database schema for a road map and thinking about the best possible model.I have following queries in my mind that need to be tackled like
Do streets s1 and s2 intersect?
Get all streets adjacent to point of interest p.
OR
Get the distance between entrance e1 and exit e2 on highway h.
Get the shortest route from intersection i1 to intersection i2.
I thought the table names should
roads and streets, including highways
governmental regions: states, counties, and local municipalities of cities, towns, villages
I have strong expertise in Database modeling, but this is first time I am creating a schema like this, Any help in this regard
As per SO rules, OP have to show some effort , I have seen some similar questions thats why I am asking for help in schema.
You need to have nodes and edges - for inner solving your tasks. (short way and so on)
You need the roads and streets and regions you have told about to translate from your inner model to human language. Also, don't forget the point objects: bus stops, crossroads, house entrances, phone booths, shops atd.
So, you need two models and a structure and a set of methods for translation between them.
Inner model:
Table: NODE Table: EDGE
Id Id
place(REGION.Id) Start(Node.Id)
End (Node.Id)
Length
road (ROAD.Id) (to what road belongs)
Outer Model:
Table: ROAD Table: Crossroad Table:REGION
Id point (NODE.Id) Id
Level Id Name
Name Level
Parent (REGION.Id)
You will need to know if roads intersect. The answer to that question should be in your database model.
It is the most important question you can have.
I would say that you need to organize your information around intersections. What road of which type is present at intersection at GIS location (x,y)?
There is only one table for roads, but each road can be of different types. Sometimes can a road be different types of road, yet have the same traffic rules. To get that distinction within the model would I make a distinction between type of road and effective type of road.
A first entrance for a data model is: http://www.osgeo.org/.
EDIT: take a look for instance at this link on that site:
http://live.osgeo.org/en/index.html
There can you download a distribution that enables you to test different open source geospatial software.
This might be exactly what you are looking for:
http://mapguide.osgeo.org/

Record relationships within one table?

I'm trying to implement my own NACE code database, and have found a .CSV file with all the codes and their respective names so that I don't have to enter them all by hand.
Problem is, the codes are all in one .CSV file. Is it possible to dump them[NACE codes] all into one table and then somehow distinguish the parent-child relationships between them all?
So, for example if all the codes are imported into table names "tnacecodes":
J62 - Computer programming, consultancy and related activities
will be the parent of
J62.0.1 - Computer programming activities
J62.0.2 - Computer consultancy activities
J62.0.3 - Computer facilities management activities
J62.0.9 - Other information technology and computer service activities
even though they are all in one table.
What I will do with this is create PHP page with nested links. By clicking on a higher level NACE codes(i.e. J62) the PHP script will retrieve the sub related codes(J62.0.1, J62.0.2,...) and display them on the page.
You can add a column with a parent link for each item. This allows a hierarchical structure (conceptually) in a single table. You can access the children of an item by searching for items with parent links to that item.

GIS project advice

Hello:
I have the following:
1. Shapefile of the world with the boundaries of each country
-- Successfully imported shapefile into PostGIS database
-- Can display map of the world in a browser via Openlayers.
2 A data (CSV) file where each record has
a. birth country,
b. gender,
c. lat and long of the country of birth (which matches the lat & long in the shapefile)
I am trying to figure out the best approach to display a map where each country (based on the CSV data) that has a 100 or more people with a color say red or green....
So my question is:
If I create a separate table with the CSV data, is there a way link this table with the shapefile table to do the above?
OR
Do I need to merge the CSV data into the shapefile table in order to accomplish the above
I am using PostGIS, mapserver and Openlayers
Thanks
Chris
I would import data from CSV file to the same PostGIS database and then create a view on two tables that would have country name and number of people(calculated from data in CSV file).
Then I would create a WMS in Mapserver from this view with SLD where I specify which color every country gets depending on number of people.
You can import a Sharefile into geoserver and geoserver will provide a WMS resource that OpenLayers can read.
I am not too sure about how to integrate CSV data b/c it has been a while. Perhaps you can just make each country have its own DOM id and just alter CSS with different background-color after map is rendered using javascript.
#chris the .dbf file should have non-geographic data such as the data about birth country and gender.
Another good example is a Shapefile from US Census Bureau. Typically the dbf file will have Census data / demographic data; but not geographic data.