Different results using JCoord and GeoTools - coordinates

I have been trying to covert Easting and Northing values to lat/lon using JCoord and GeoTools. Problem is I am getting different results for each library using the same Easting & Northing.
The code I am using is the code provided in the main answer and GeoTools answer provided in this question.
convert latitude and longitude to northing and easting in java?
The easting I am using is : 393339
The Northing I am using is : 806179
The coordinates Jcoord is providing are (57.14645296506957, -2.111698674790966)
The coordinates GeoTools is providing are [57.146449494619105, 2.111714868502565]
They seem to lose accuracy around the 4th digit and I'm wondering which one is right??
Thanks

Assuming that these are OS Eastings and Northings (which seems likely based on your lat/lon values) then they are accurate to 1m (as 6 figure grid references). Based on the values given by this calculator a degree of latitude is around 100 km so the 4th decimal point is roughly 10m or about the accuracy you can expect.
To get more precision out of the calculation you need to make sure of the ToWGS84 parameters being used in each calculation - for GeoTools you can query the projection to find this value, I expect JCoord has a similar operation.
Note in GeoTools the towgs parameter may vary depending on which referencing factory you are using, I believe that gt-epsg-hsql is more accurate than the gt-epsg-wkt.

Related

Longitude and Latitude LOCF values in TimescaleDB

If I store longitude and latitude as numeric values in 2 columns, can I get the average values of them with in a time bucket? and locf(last observation carry forward) value too? Will that average geo spatial value be accurate as it should not be just the mean value for co-ordinates?
What are the available functions for gps coordinates in timescaleDB?
can I get the average values of them within a time bucket? and locf(last observation carry forward) value too?
Yes, take a locf function. It can also be combined with avg or any aggregation functions from Postgres.
Will that average geospatial value be accurate as it should not be just the mean value for coordinates?
You can try to preview the values in a small set as this example.
Also, almost all other Postgres extensions can be combined here. PostGIS is probably the most advanced extension for it.

Best practice for unit conversion between imperial and metric

I have an app I'd like to open up to an international audience & so I need to accept different units, to keep it simple let's say miles & kilometers.
I figured I've got 3 options:
Use Meteor's transform option on my collection
Use Simple Schema's autoValue
Manually adjust the value every time I send/receive it from the DOM
Store mi/km in different fields (take advantage of that NoSQL!)
?
What is the pattern you've found most useful? Any examples would be great.
For smaller units of measure like yards and meters, I would use an integer of centimeters. It can be converted to any unit larger than itself easily and you shouldn't have any issues with floats. On a scale of miles and kilometers, I'd store integers of meters.
As far as how to transform them back and forth, I'd keep that in the view, not the model. I'm not a meteor guy so I'm not sure how that translates, but I'm saying I'd use javascript to either multiply meters by 1000 for kilometers or by 1609 for miles. There's even Javascript libraries to assist in this kind of internationalization.

Zillow Neighborhood data and STDistance

I am working with Zillow neighborhood data provided freely at http://www.zillow.com/howto/api/neighborhood-boundaries.htm . I have successfully Imported the data with SRID 4120. Now I am trying to find out the neighborhoods by giving a coordinate(lat,long) and a radius. Finding a neighborhood in which my point exists is easy and is done through STIntersect method. I am actually confused with STDistance. For complete WA state data, It is giving me a maximum distaince of 4.xxx relative to any point in the wa. My question is what is the good way to find the points which are in a given radius and what is the unit.
thanx
zAfar
Got it, I was importing geography data into geometry column.

Query to find distance between a point column and a point in PostGis

I am using PostGis for Location based calculations in my Application. In a Table i have a column called 'location' in geography type(Point(lon lat))...Like this number of rows present in the Table.
I want to pass a point(Point(lon lat)) and check distance between this point(i passed) and location column in all rows....and if distance is less than 5 m....it will return the name of the point.How to query this.
Assuming that your srid of your data is 4326 the query you are looking for is:
SELECT the_geom FROM mytable WHERE ST_DWithin(the_geom,ST_GeomFromEWKT("srid=4326;POINT(lon lat)"), 0.0008);
Note that the units(0.0008) in ST_DWithin are in the same units of your projection, in the 4326 case they are degrees. If your projection data is in meters, you will be able to use meters.
For a production application you should use geometry types, is faster. From a stackoverflow previous question:
Short Answer: geography is a new data type that supports long range
distances measurements. If you use geography -- you don't need to
learn much about planar coordinate systems. Geography is generally
best if all you care about is measuring distances and lengths and you
have data from all over the world. Geometry datatype is an older data
type that has many functions supporting it and enjoys great support
from third party tools. Its best if you are pretty comfortable with
spatial reference systems or you are dealing with localized data where
all your data fits in a single spatial reference system (SRID), or you
need to do a lot of spatial processing. Refer to Section 8.8, “PostGIS
Function Support Matrix” to see what is currently supported and what
is not.
Great.Thank You. It works fine in database. I have following code from PHP..it returs like, Query Failed:
$locationresult=pg_query($con,"SELECT id,name FROM gps.locationnames WHERE ST_DWithin(location,ST_GeographyFromText('POINT(lon lat)'),500)") or die ('Query Failed:'.pg_last_error($con));
What is the problem here..

What SRID should I use for my application and how?

I'm using PostgreSQL with PostGIS. All my data has already decimal lat/long attached to it (i.e. -87.34554 33.12321) but to use PostGIS I need to convert it to a certain type of SRID.
The majority of my queries are looking for data inside a certain radius.
What SRID should I use? I created already a geometry column with SRID 4269.
In this example:
link text the author is converting SRID 4269 to SRID 32661. I'm very confused about how and when to use these SRIDs. Any lite on the subject would be truly appreciated.
As long as you never intend to reproject/transform the data to another coordinate system, it doesn't technically matter what srid you use. However assuming you don't want to throw away that important metadata, and you do want to transform it, you will want to ensure your assigned srid matches the data, so postgis knows what to do when the time comes.
So why would you want to reproject from epsg:4269? The answer is because certain types of queries (such as distance) make no sense in this 'unprojected' world. Your units are in decimal degrees, and a straight measurement of x decimal degrees is a different real distance depending where in the planet you are.
In your example above, someone is using epsg:32661 as they believe it will give them better accuracy for the are they're working in. If your data is in a specific area of the globe, you can select a projection that's accurate for that area. If it spans the entire globe, you have to choose a projection that does 'ok' for your needs.
Now fortunately PostGIS has a few ways of making all this easier. For approx distances you can just use the st_distance_sphere function which, as you might guess, assumes the earth is a sphere. Or the more accurate st_distance_spheroid. Using these, you don't need to reproject and you will probably be fine for your distance queries except in edge cases. Newer versions of PostGIS also let you use geography columns
tl;dr - use st_distance_spheroid for your distance queries, store your data in geography columns, or transform it to a local projection (when storing, or on the fly, depending on your needs).
Take a look at this question: How do you know what SRID to use for a shp file?
The SRID is just a way of storing the WKT inside the database (you may have noticed that, altough you store lat/long points, the preferred storing is a long string with number and capital letters).
The SRID or EPSG can be different for the country/state/... altough there are some very common ones especially the 2 mentioned by you. If you need specific info what area uses what SRID, there is a database for handling that.
Inside your database, you have a table spatial_ref_sys that has the information on what SRID PostGIS knows about.