Geoserver - How do I draw a geodesic line that represents the great circle between two points - postgresql

I'm using Geoserver version 2.1.1, Postgres 9 and PostGIS 2.0
What I want to achieve should (i think!) be quite straight forward. I want to render on a map a line that represents the Great Circle between two cities on the earths surface.
My database contains the city locations represented as geography points defined as latitude and lonfitude pairs.
I have a layer defining an SQL view in Geoserver which retrieves a linestring (st_makeline) from the two coordinates for the specified cities. I'm having to type cast the geographies to geometries to get this to work.
But when I draw the returned line on a map what i get is a straight line and not the curved line that I am expecting.
Can someone tell me how I should be going about this?
Thanks!

PostGIS offers mainly "constructors" of the base geometries point, linestring and polygone, like ST_MakeLine.
And what yo uwant to do depends also on the coordinate reference system you use when displaying your map layers.
Here's a nice trick about great circles or parts of:
https://gis.stackexchange.com/questions/5204/curved-point-to-point-route-maps
Yours, Stefan
P.S. Here's some related stuff:
Drawing circles on a sphere
And here's some math:
http://www.mathworks.ch/matlabcentral/newsreader/view_thread/277881

I had a similar problem in cartodb (which also uses PostGIS); I wanted to get curved lines from straight lines. Maybe this post can help.

Related

Using leaflet to determine if a line intersects through a polygon

I am trying to work out the best way to determine if a line goes through a polygon, where it is possible that that points on that line do no fall within the polygon as shown in image below.
My data is multiple polygons and I wish to see if a line (lat,long to lat,long) goes through 1 or more of the polygons.
leaflet has a leaflet-pip that does a point in a polygon but I need to test a line... turf.js has lineIntersect but would this work with a line and a polygon (JSON)? Is there something else I can use but haven't found yet?
Just after some advice on the best way or library to achieve this
Thank you.
turf booleanIntersects works nicely.
Example here: https://codesandbox.io/s/ripkk?file=/src/index.js:9634-9641

Using leaflet to determine if a line intersects through a polygon [duplicate]

I am trying to work out the best way to determine if a line goes through a polygon, where it is possible that that points on that line do no fall within the polygon as shown in image below.
My data is multiple polygons and I wish to see if a line (lat,long to lat,long) goes through 1 or more of the polygons.
leaflet has a leaflet-pip that does a point in a polygon but I need to test a line... turf.js has lineIntersect but would this work with a line and a polygon (JSON)? Is there something else I can use but haven't found yet?
Just after some advice on the best way or library to achieve this
Thank you.
turf booleanIntersects works nicely.
Example here: https://codesandbox.io/s/ripkk?file=/src/index.js:9634-9641

Check intersections between points and polygons in QGIS

I have two data layers, one with points and one with polygons. Both layers have ID's and I would like to check whether the points with ID x lay inside or outside the polygon with ID x.
Does someone know how to do this?
Thanks,
Marie
One potential solution which gives you a comma separated list in the python console is to run a small script from the python console:
mapcanvas = iface.mapCanvas()
layers = mapcanvas.layers()
for a in layers[0].getFeatures():
for b in layers[1].getFeatures():
if a.geometry().intersects(b.geometry()):
print a.id(),",",b.id()
This should produce a result of cases where one feature intersects the other. The order of the layers did not matter in my testing, however, both layers had to use the same coordinate reference system, so you might need to re-project your data if both layers have different reference systems. This worked for points in polygons and polygons intersecting polygons (I'm sure it would work with lines as well).
Answers such as this: https://gis.stackexchange.com/questions/168266/pyqgis-a-geometry-intersectsb-geometry-wouldnt-find-any-intersections may help with further refinement of such a script, and was a primary source on this answer.

How can to do shape math with bing maps?

If I have two shapes displayed on Bing-Maps can I do any set Math?
What I really want is to take two intersecting shapes, determine a 3rd shape for the intersection and then reduce the the original shapes to exclude the intersection.
I actually have the intersection shape so the key bit is taking a 'bite' out of the original shapes.
Reason for doing this is currently displaying the intersection as a third layer (to give a specific colour) produces a largely occluded map, what with part of the transparent shape1 and shape2 and the intersection all covering the same bit of the map.
If I could 'cut-down' the two main shapes only the intersection shape would colour/cover that part of the map.
I do not think there are out of the box solutions in the Bing Maps API. I have done something similar in the past with Bing Maps API and SqlGeography Class though. Its easy to loop through the points of our Bing Polygons, therefore we can plot them into SqlGeography Polygons or SqlGeometry Polygons.
You will need the Microsoft.SqlServer.Types.dll to make use of this class, but it is free with SqlExpress.(Note that you do not actually need SQL Server installed, you just need to reference the DLL)
You can use the SqlGeography Class (or SqlGeometry Class) to find intersecting shapes and points. Perhaps have a look at STIntersection Method, According to MSDN STIntersection will;
"Returns an object representing the points where a SqlGeography instance intersects another SqlGeography instance."
Once you have the object representing the shape were a SqlGeography instance intersects another, you know you need to somehow adjust any points from the compaired instances that lie withing the SqlGeography instnace returned by StIntersection.
Here is a simular question where Peter uses STDifference. To subtract the two shapes.
I'll provide you with a c# example I made quickly for the Intersection. I had a lot of trouble finding any code examples for anything that wasn't purely SQL Server based.
SqlGeography Shape1 = new SqlGeography();
SqlGeographyBuilder geographyBuilder1 = new SqlGeographyBuilder();
geographyBuilder1.SetSrid(4326);
geographyBuilder1.BeginGeography(OpenGisGeographyType.Polygon);
geographyBuilder1.BeginFigure(47.4275329011347, -86.8136038458706);
geographyBuilder1.AddLine(36.5102408627967, -86.9680936860962);
geographyBuilder1.AddLine(37.4928909385966, -80.2884061860962);
geographyBuilder1.AddLine(38.7375329179818, -75.7180936860962);
geographyBuilder1.AddLine(48.0932596736361, -83.7161405610962);
geographyBuilder1.AddLine(47.4275329011347, -86.8136038458706);// Remember last point in the polygon should match the first
geographyBuilder1.EndFigure();
geographyBuilder1.EndGeography();
Shape1 = geographyBuilder1.ConstructedGeography;
SqlGeography Shape2 = new SqlGeography();
SqlGeographyBuilder geographyBuilder2 = new SqlGeographyBuilder();
geographyBuilder2.SetSrid(4326);
geographyBuilder2.BeginGeography(OpenGisGeographyType.Polygon);
geographyBuilder2.BeginFigure(47.4275329011347, -86.8136038458706);
geographyBuilder2.AddLine(36.5102408627967, -86.9680936860962);
geographyBuilder2.AddLine(37.4928909385966, -80.2884061860962);
geographyBuilder2.AddLine(47.4275329011347, -86.8136038458706);
geographyBuilder2.EndFigure();
geographyBuilder2.EndGeography();
Shape2 = geographyBuilder2.ConstructedGeography;
SqlGeography IntersectedShape = Shape1.STIntersection(Shape2);
I believe you can draw shapes with the new GeoRSS feature - it supports line, boxes, polygons and circles. GeoRSS was designed as a lightweight, community driven way to extend existing feeds with geographic information. Also check out GeoJson

Identify different shapes drawn using UIBezierPath?

I am able to draw shapes using the UIBezierPath object. Now I want to identify different shapes drawn using this eg. Rectangle , Square , Triangle , Circle etc. Then next thing I want to do is that user should be able to select a particular shape and should be able to move the whole shape to different location on the screen. The actual requirement is even more complex , but If I could make this much then I can work out on the rest.
Any suggestion or links or points on how do I start with this is welcome . I am thinking of writing a separate view to handle every shape but not getting how do I do that..
Thank You all in advance !!
I recommend David Gelphman’s Programming with Quartz.
In his chapter “Drawing with Paths” he has a section on “Path Construction Primitives” which provides a crossroads:
If you use CGContextAddLineToPoint your user could make straight lines defined by known Cartesian points. You would use basic math to deduce the geometric shapes defined by those points.
If you use CGContextAddCurveToPoint your user could make curved lines defined by known points, and I’m pretty sure that those lines would run through the points, so you could still use basic math to determine at least an approximation of the types of shapes formed.
But if you use CGContextAddQuadCurveToPoint, the points define a framework outside of the drawn curve. You’d need more advanced math to determine the shapes formed by curves along tangents.
Gelphman also discusses “Path Utility Functions,” like getting a bounding box and checking whether a given point is inside the path.
As for moving the completed paths, I think you would use CGContextTranslateCTM.