Problem with location aware XML file - iphone

I am making location aware application. I have XML file on server containing information of different stores with latitude and longitude coordinates.
Now in my application i can get my current latitude and longitude coordinates and can parse XML file as well.
But how can i figure out nearest store according to my current coordinates from XML file?
If we use google Api it returns you xml file containing nearest locations according to query. but here in my case i am using xml file on server.
Please suggest

I think you'd be better off converting your data into a DB format (sqlite/mysql) so that the user can submit their lat/Lng point and just get the correct item returned...otherwise you'd need to parse and compare the whole file each time...but, you can still use that formula (it's really just shifting the comparison step to the DB query rather than within your app)
Edit: this has an example of a SQL query that implements haversine and returns x results: MySQL Great Circle Distance (Haversine formula)

This is the haversine formula for calculating distance between two points on the earth:
a = sin²(Δlat/2) + cos(lat1)*cos(lat2)*sin²(Δlong/2);
c = 2*atan2(√a, √(1−a));
d = R*c;
You can easily adapt it in obj-c.
Please note: R is radius of the earth = 6,371km;
So just calculate the latitude and the longitude difference of both points and calculate d based on it.
Hope this helps.

Related

How to convert EPSG:28992 to EPSG:4326?

I have a list of coordinates which i need to convert to longitude and latitude in the folowing way:
What are the math transformations and formulas used to achieve this?
QGis might also be helpful to convert between several projections.
Once you can see your geometry as layer in Qgis, right click on the layer and select
Export => Save Features As ... and select the wanted format.
https://www.qgis.org/en/site/forusers/download.html

Google Data Studio Geo Map stays blank while using Lat,Long as Dimension

I want to use Google Data Studio to visualize the location of NGO´s in Europe. Some of these share the same HQ Location in the Data e.g. Italy Rome. Idea is to transfer these into Lat,Long coordinates and slightly manipulate the values to show them with their name in the GMaps bubble diagram. The original data is unfit, because the digram cannot display multiple tooltips/names for the same location.
I have been following this guide https://michaelhoweely.com/2020/05/04/how-to-build-a-custom-google-map-in-data-studio-using-google-sheets-and-geocode/ to do the Geo Coding of the locations.
Problem is that the Geo Chart goes blank if I choose Lat,Long as the location dimension. Even the original data (not modified by me) will cause the same issue.
GDataStudio_Lat_Long_Vis_Issue
Any idea of what I am doing wrong here or having a better idea of how to do the visualization?
You also have to make sure you change the type to GEO, as it sometimes defaults to ABC or numeric.
It may help to concatenate the latitude and longitude values to follow the WKT format, as shown below.
CONCAT(<longitude_column>, ", ", <latitude_column>)
In the current state, the latitude and longitude are reversed, so the error is probably caused by each value exceeding the default range for latitude and longitude.

In Tableau Map plot multiple sites at same lat long

I have a data where at one latitude and longitude multiple shops are located.
For Example.
Latitude Longitude ShopId Type
6.24458 50.001756 101 Saloon
6.24458 50.001756 102 Groceory
6.24458 50.001756 103 Pharmacy
6.24458 50.001756 104 FishMarket
When on map I am plotting using above latitude & longitude I am getting single mark. And when I hover the mark I am getting single shop details but I want 4 marks and on each mark it should show respective shopid and Type.
I am new to Tableau and not able to figure out how to do it.
You are likely getting 4 marks displayed at the same location. So when you click on the mark you see, then you are only selecting the top mark. You can verify this by dragging over the mark to select all the marks within a selection rectangle. If you then, right click and view data, you should see all 4 marks.
Another thing that can help when you have overlapping marks, is to make the marks partially transparent and add a border around the marks. Both options are available by clicking on the Color button on the marks card to get to the advanced color settings.
If this is not the behavior you want, you have a couple of options. One easy approach is to add a little random noise to each latitude and longitude (called jitter). Adding a little jitter makes the marks visible, although the size of the jittering depends on your data and scale. Jittering is especially useful if all your points are geocoded to the same situation - say if every building with a Los Angeles address is treated as if it is located at city hall. In that case, the geocoding distorts the data to a degree that jittering is just fine.
The undocumented RANDOM() function is an easy way to add some jitter. Excel and Hyper Extracts support RANDOM() among other data source types. It returns a number between 0 and 1.
The other options involve treating your coordinates as continuous dimensions instead of measures, and then using some other visual attribute size, color etc to indicate the number of items at each location. It is often useful to combine nearby items with some sort of grid or hex bin function -- In this case, instead of adding random noise to each coordinate, you round or truncate it in someway to effectively snap points to a grid. The ROUND() and HEXBINX() HEXBINY() functions are useful here. When using this approach, be sure your packed coordinate fields are continuous dimensions and have the appropriate Latitude or Longitude geographic role.
Finally, take a look at the density mark type. It can make visual heat maps, either working with exact data points or grid packed points.

Put points on the map, longitude/latitude not where they should be although SRID the same

Thank you for looking at this - I'm sure it's a simple question but this is all very new to me and after a lot of internet searching my points are still in the sea!
I have a set of UK postcode data that I have converted into latitude and longitude. I also have a UK counties shape file.
The code that I have used to convert the latitude/longitude to a geometry point column is as follows:
ALTER TABLE colic ADD COLUMN longlat geometry(POINT,27700);
update colic set longlat = st_setsrid(st_point( longitude, latitude), 27700);
And this produces a column that has values as follows (I've only included a couple!):
"0101000020346C000048BF7D1D3867E83FC05B2041F1334A40"
"0101000020346C0000F085C954C1A8F7BFA1F831E6AE954A40"
"0101000020346C000020D26F5F07CEF4BFE3361AC05B504A40"
"0101000020346C00007D3F355EBA49F73FB6847CD0B3614A40"
The .prj from my shape file is:
PROJCS["British_National_Grid", GEOGCS["GCS_OSGB_1936",
DATUM["D_OSGB_1936", SPHEROID["Airy_1830",6377563.396,299.3249646]],
PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",400000.0],
PARAMETER["False_Northing",-100000.0],
PARAMETER["Central_Meridian",-2.0],
PARAMETER["Scale_Factor",0.9996012717],
PARAMETER["Latitude_Of_Origin",49.0], UNIT["Meter",1.0]]
And I set its SRID to 27700 when I upload it using the PostGIS shapefile uploader.
In PG Admin, when I ask:
select st_srid(geom) from counties limit 1;
select st_srid(longlat) from colic limit 1;
I get 27700 for both.
But...when I try any spatial query I get no response, and when I load the layers into quantum, the point data are off the tip of Cornwall in the north Atlantic, and only represented as one dot on the scale of the counties map.If I zoom in on them, they are 'there', but just not in east anglia where they should be!
This is my first attempt at both SQL and mapping - I'm sure there is something really simple that I have missed.
You are mixing up spatial references (SRS). The SRS in the .prj file (aka SRID=27700) is projected eastings and northings, which have units of metres. This is not latitude and longitude! Furthermore, it is a deception to call a column longlat when it isn't for longitude/latitude coordinates.
If you try to insert latitude/longitude in a column with SRID=27700, the points will not behave as expected, e.g., they will be in the far bottom left corner of a map.
If you have lat/long data from WGS84 (SRID=4326), you can transform this to eastings and northings:
UPDATE colic SET
geom = ST_Transform(ST_SetSRID(ST_Point(longitude, latitude), 4326), 27700);

Extracting data from grib file based on latitude and longitude

If i have a grib2 file that contains information for whole world (for some parameters) and I want to extract data from it using wgrib2 based on latitude and longitude given by user (client software to server). I tried following command but I am getting complete grib2 file only:
wgrib2.exe input.grb -undefine out-box 10:90 -10:10 -grib output.grb
Please tell me where am I going wrong? Thanks.
This is still the top hit on Google, so even though it is a bit old, here is a more detailed explanation.
First, you need wgrib2 from the National Weather Service Climate Prediction Centre. (The installation of that is straightforward, but not too well explained. See this page, or this gist for help.)
Next, you need to use the lola function (for LOngitude-LAtitude grid).
You need to give wgrib2 several arguments:
the grib file that has the data
the longitude information:
the longitude of the southwest corner of your bounding box
the length of the bounding box in degrees
the spacing of the points in this direction
the latitude information, the same as above
the latitude of the southwest corner of your bounding box
the length of the bounding box in degrees
the spacing of the points in this direction
the file name to write to
the format of the file to write (either bin for binary, text for simple text, spread for spreadsheet format, or grib for grib2).
For example:
wgrib2 input.grb 220:100:1 20:50:1 output.grb2 grib
will create an output file that covers north america (220 E - 320 E; 20 N - 70 N) at 1 degree intervals in both directions.
Rob
I used the following command to extract information from grib2 file.
wgrib2.exe input_file.grib2 -lola LonSW:#lon:dlon LatSW:#lat:dlat file format
assuming that we are having following co-ordinates for selection:
Top: (x0,y0) (x1,y0)
Bottom: (x0,y1) (x1,y1)
"LongSW"=x0, #lon = (x0~x1), "LatSW"=y0, #lat = (y0~y1).
and dlon and dlan can be kept as 1. 'file' is the output file name and format can be grib, csv, text etc.
Substitute above values in the command shown above and you should get the answer.
If your chosen longitude was 360 and latitude was 90:
wgrib2.exe input_file.grb2 -lon 360 90 > output_file.txt
I think you can also use cdo directly on grib for this
cdo sellonlatbox,lon1,lon2,lat1,lat2 in.grb out.grb
If the grib file is on a reduced gaussian grid you may need to specify that you want a regular lat-lon output. I usually convert the output format to netcdf myself using "-f nc" as I find it easier to process in other software.