Difference between multipolygon and polygon in PostGIS - gis

What is the difference between point and multipoint ? linestring and multilinestring ? polygon and multipolygon ? In PostGIS
What is the secret behind defining "Multi" shapes?

"Multi" means, that several objects of that kind are "grouped" together to single object. For example, imagine Philippines. That country consists of lot of islands - you can't draw it with single polygon; and it would be inconvenient to store it as several different database rows, each containing single polygon.

Related

MySQL Spatial Object for multiple polygons that may or may not be connected

I have a set of of polygons. Sometimes they are completely disconnected (like separate patches). Other times, two sides of two polygons may touch each other (when the polygons are adjacent like on a chess board). The polygons never cross each other. In other words, their intersection is always empty.
I need to check if a point is contained in any one of those polygons. Is there a way I can build a single geometry using these polygons and check if the point is in it?
Currently I'm building a long WHERE close with OR conditions and do something like the below:
st_contains(st_GeomFromText('POLYGON(("+polygon+"))'), st_GeomFromText(CONCAT('POINT()')))
Thanks.

Mysql two points to be checked if they are in rectangles

I'm in a process of developing an application and I would appreciate some help regarding an idea how to store data in mysql table.
I have two points - point A and point B which are start and end point.
I've already wrote some php function that will create rectangles similar to:
http://googlegeodevelopers.blogspot.com/2010/05/search-along-route-made-easy-with.html
However depending on the route and radius it generates different amount of rectangles. What is the best way to save those rectangles into the database, so later I can query the DB and check if another two points (start/end) are in any of those rectangles.
Can you give me an example?
The easiest way to do it is to store your rectangles as polygons, per
http://dev.mysql.com/doc/refman/4.1/en/polygon-property-functions.html
You can then use MBRIntersects to figure out if they intersect (or use MBRWithin or MBRContains, if you'd prefer), per
http://dev.mysql.com/doc/refman/5.1/en/functions-for-testing-spatial-relations-between-geometric-objects.html#function_mbrintersects
For funky-shaped polygons, this isn't adequate, but the MBR (minimum bounding box) of a rectangular bounding box will be exactly the same as the rectangle itself.

Calculating the centroid from points in a MySQL-table

In a MySQL-table I have a column of the "point" geospatial datatype. Is it posssible to calculate the centroid of all the point-values of all rows directly in MySQL?
The aim of my project is to put the center of a map at the centroid of the points that it contains.
One potential solution is given in the MySQL documentation: Centroid(mpoly). But this would mean that I had to concatenate all points' values externally in a programming language and then send the resulting query back to MySQL. This sounds quirky to me.
A centroid is simply the intersection of the mean X and Y values, so the following should work:
SELECT
POINT( AVG(X(geographic_location)), AVG(Y(geographic_location)) )
FROM poles

GIS: Converting multi polygons to multiple features

I am involved in a GIS project. I have a base map file (shape file) that contains the road layer for a large portion of a town. The problem is that the shape file contains only two features each containing around 500000 points each. The features are multipolygons containing a large no of polygons inside. I wish to convert it to numerous features each containing not more than one polygon. Is it possible? If yes, how?
Seems like what you have here is a multi-part feature. If you are using ArcGIS, you need to add the advance editor toolbar in your arcmap. Start an editing session and use the explode multi-part feature tool and then you will have one geometry for each record.
If you have connectivity information (e.g. you have polygons and not just points) it's not too tough to do a decent job of polygon reduction.
What I've done in the past consisted of two steps.
Any vertex that is surrounded by polygons, all of which are coplanar, can be removed. I did this by "sliding" the vertex to a neighbor vertex, that neighbor getting all of the test vertex's neighbors and any triangles that become degenerate (e.g. any triangles shared between the two vertices) were removed.
Any vertex which has two edges leaving opposite one another, where the polygons on either side are either completely nonexistent or are coplanar can also be similarly collapsed into a neighbor vertex, but obviously only one that is along one of the parallel edges.
note-
Two polygons are coplanar if they share at least one point in common and if they have the same normal. Since the candidate polygons are always attached to the candidate vertex, you just need to compare polygon normals. The normal can be computed by taking the cross product of two of the edges of the polygon.

How to very efficiently assign lat/long to city boundary described by shape?

I have a huge shapefile of 36.000 non-overlapping polygones (city boundaries). I want to easily determine the polygone into which a given lat/long falls. What would the best way given that it must be extremely computationaly efficient ?
I was thinking of creating a lookup table (tilex,tiley,polygone_id) where tilex and tiley are tile identifiers at zoom levels 21 or 22. Yes, the lack of precision of using tile numbers and a planar projection is acceptable in my application.
I would rather not use postgres's GIS extension and am fine with a program that will run for 2 days to generate all the INSERT statements.
Insert statements into what? Are you using a different spatial database or some other database? If you are willing to use python, C, or Java you could use shapely, GEOS, or JTS to write some custom code to do what you want rather simply.
In python use this lib to open the shapefile
http://indiemaps.com/blog/2008/03/easy-shapefile-loading-in-python/
then shapely
http://gispython.org/shapely/docs/1.0/manual.html#contains
to test containment
For Java use Geotools which also includes JTS.
Sounds like you want a BSP tree. Basically you divide the area into smaller and smaller polygons in a tree like fashion.
The advantage is that you don't need to compare coordinates with every polygon later on. That makes it a very fast way to find the correct polygon.