Adding the distance between two zip codes to a data file - zipcode

What is the best way to calculate AND add a field to a data file that shows the crow-fly distance (in miles) between two zip codes for each record (250K+) in a file? THANKS

Use this page for the raw distance information. Then use this website for the formula from Adam Bellaire's response to calculate the distance.
There is no reason to use an external service as zip codes really don't change all that often.
Enjoy!

Get a Google Earth API Key and use the API to calculate distances between two zip codes in your language of choice.
UPDATE:
If a web service isn't for you, you can check my OLD Visual Basic Posting on planet source code. It has a database of zip codes, their lat/long positions, and some VB code to calculate the distances between two zip codes. The Zipcode DB will probably require some updating, and it's in a MS Access format (but you can move that data anywhere).

You could use the Yahoo Geocoding Service to first get the latitude and longitude corrodinates for each zip code, then simply use the haversine formula to get the distance between any two sets of latitude/longitude data.
Here is a c# implementation of the haversine formula.
Enjoy!

Related

CDO mergegrid applicable on a non-rectilinear grid?

I have 16 netcdf files (without a time dimension) on a global scale that contain the same amount of longitude grid points (namely 432) and the same amount of latitude grid points (namely 324). Each netcdf file contains a slice of data, for example in file 1 there is a data slice from latitude range 90 to 80 and in file 2 there is data available from latitude range 80 to 70. I want to merge these files which each contain a different slice of data to obtain a complete global dataset.
I have tried to merge the netcdf files with cdo mergegrid as described in this answer https://stackoverflow.com/a/51566286/20668027 and that worked as far as I could see, however, when looking in the cdo guidelines it was stated that cdo mergegrid is only supported for rectilinear grids. The grid that I am using is not rectilinear but since it seemed to work on my data I was wondering if I could still use cdo mergegrid? Does anyone have insights about this?
Thank you very much in advance!
The NCO equivalent to CDO ensmean is nces described here. You could try
nces in*.nc out.nc

Given a OSM node id, how do I find the previous x points in all directions?

I have a OSM node Id/ latitude-longitude for a point in the road(say point Z). How do I find the previous x points that I need to travel to reach Z in all directions? I was thinking overpass API could help me. But it is able to return points only with tags. I am not able to get it return the node Ids on the road/way.
Can you please suggest any API/tutorial that could help?
if i'm not wrong what you are asking is: given a osm node id with coordinate x and y what are all points to do in order to arrive there from a starting point?
if this is the question well this is a graph oriented question; you should create a grah and then use some algorithm in order to find all the routes between starting point and end point; you should use some graph oriented software.. something like neo4j and spatial contrib (https://github.com/neo4j-contrib/spatial)
In past i built a project where i read an osmfile, create a graph and used A* algorithm; you may give to it a look https://github.com/angeloimm/neo4jAstarTest
I suggest to get started by reading about OSM elements, especially nodes and ways. Afterwards take a look at OSM XML format. It might also help to open an OSM editor (e.g. iD) and to take a look at the raw data.
Nodes don't have any order or "next node" themselves. Nodes can be part of one or multiple ways. Each way references a list of ordered nodes. So you have to look at all ways a node belongs to, then look at the way's node list to determine the previous and next nodes. If the node is at the start or end of a way then you have to look if there are one or more consecutive ways. Consecutive ways share the same node at their start/end.

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.

Calculation route length

I have a map with about 80 annotations. I would like to do 3 things.
1) From my current location, I would like to know the actual route distance to that position. Not the linear distance.
2) I want to be able to show a list of all the annotations, but for every annotation (having lon/lat) I would like to know the actual route distance from my position to that position.
3) I would like to know the closest annotation to my possition using route distance. Not linear distance.
I think the answer to all these three points will be the same. But please keep in mind that I don't want to create a route, I just want to know the distance to the annotation.
I hope someone can help me.
Best regards,
Paul Peelen
From what I understand of your post, I believe you seek the Haversine formula. Luckily for you, there are a number of Objective-C implementations, though writing your own is trivial once the formula's in front of you.
I originally deleted this because I didn't notice that you didn't want linear distance at first, but I'm bringing it back in case you decide that an approximation is good enough at that particular point of the user interaction.
I think as pointed out before, your query would be extremely heavy for google maps API if you perform exactly what you are saying. Do you need all that information at once ? Maybe first it would be good enough to query just some of the distances based on some heuristic or in the user needs.
To obtain the distances, you could use a Google Maps GDirections object... as pointed out here ( at the bottom of the page there's "Routes and Steps" section, with an advanced example.
"The GDirections object also supports multi-point directions, which can be constructed using the GDirections.loadFromWaypoints() method. This method takes an array of textual input addresses or textual lat/lon points. Each separate waypoint is computed as a separate route and returned in a separate GRoute object, each of which contains a series of GStep objects."
Using the Google Maps API in the iPhone shouldn't be too difficult, and I think your question doesn't cover that, but if you need some basic example, you could look at this question, and scroll to the answer.
Good Luck!
Calculating route distance to about 80 locations is certain to be computationally intensive on Google's part and I can't imagine that you would be able to make those requests to the Google Maps API, were it possible to do so on a mobile device, without being severely limited by either the phone connection or rate limits on the server.
Unfortunately, calculating route distance rather than geometric distance is a very expensive computation involving a lot of data about the area - data you almost certainly don't have. This means, unfortunately, that this isn't something that Core Location or MapKit can help you with.
What problem are you trying to solve, exactly? There may be other heuristics other than route distance you can use to approximate some sort of distance ranking.

How do you figure out what the neighboring zipcodes are?

I have a situation that's similar to what goes on in a job search engine where you type in the zipcode where you're searching for a job and the app returns jobs in that zipcode as well as in zipcodes that are 5, 10, 15, 20 or 25 miles from that zipcode, depending on preferences set by the user.
How would you calculate the neighboring locations for a zipcode?
You need to get a list of zip codes with associated longitude / latitude coordinates. Google it - there are plenty of providers.
Then take a look at this question for an algorithm of how to calculate the distance
I don't know if you can count on geonames.org to be around for the life of your app but you could use a web service like theirs to avoid reinventing the wheel.
http://www.geonames.org/export/web-services.html
I wouldn't calculate it, I would stored it as a fixed table in the database (only to change when the allocation of ZIP codes changes in a country). Make a relationship "is_neighbor_zip", which has pairs (smaller, larger). To determine whether two codes are neighboring, check in the table for specific pair. If you want all neighboring zips, it might be better to make the table symmetric.
You need to use a GIS database and ask it for ZIP codes that are nearby your current location.
You cannot simply take the ZIP code number and apply some mathematical calculations to find other nearby ZIP codes. ZIP codes are not as geographically scattered as area codes in the US, but they are not a coordinate system.
The only exception is that the ZIP+4 codes are sub-sections of the larger ZIP code. You can assume that any ZIP+4 codes that have the same ZIP code are close to each other.
I used to work on rationalizing the ZIP code handling at a company, here are some practical notes I made:
Testing ZIP codes
Hopefully has other useful info.
Whenever you create a zipcode, geocode it (e.g. google geocoder api, saving the latitude and logitude) then google the haversine formular, this will calculate the distance (as the crow flies) from a reference point, which could also be geocoded if it is a town or zipcode.
To clarify some more:
When you are retrieving records based on their location, you need to compare each longitude and latitude DECIMAL with a reference point (your users geo-coded postcode or town name)
You can query:
SELECT * FROM photos p WHERE p.long < 60 AND p.long > 50 AND p.lat > -10 AND p.lat > 10
To find all UK photos etc because the uk is between 50 and 60 degrees longitude and +-10 latitude (i might have switched long with lat, i'm fuzzy on this)
If you want to find the distance then you will need to google the haversine formula and plug in your reference values.
Hope this clears things up a little bit more, leave a comment if you need details