Skip to content

Instantly share code, notes, and snippets.

@nathankerr
Created May 7, 2010 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathankerr/393349 to your computer and use it in GitHub Desktop.
Save nathankerr/393349 to your computer and use it in GitHub Desktop.
Alternative Approaches to Parallel GIS Processing
if(key == 1008130) {
GIS created = new GIS();
GIS.update("\"97123897\",\"POLYGON((-112.0859375 33.4349975585938,-112.0859375 33.4675445556641,-112.059799194336 33.4675445556641,-112.059799194336 33.4349975585938,-112.0859375 33.4349975585938))\",\"C\"");
output.collect(new LongWritable(new Integer(97123897)), created);
}
output.collect(key, value);
f(value.geometry.intersects(box)) {
output.collect(key, value);
}
double minDistance = Double.MAX_VALUE, currDistance;
int closestParcel = -1;
Iterator it = parcels.iterator();
while (it.hasNext())
{
GIS parcel = (GIS) it.next();
currDistance = value.geometry.distance(parcel.geometry);
if (currDistance < minDistance)
{
minDistance = currDistance;
closestParcel = new Integer(parcel.attributes.get("id"));
}
}
LongWritable lngClosestParcel = new LongWritable (closestParcel);
output.collect(key, lngClosestParcel);
if(key.equals(new LongWritable(1008130))) {
value.attributes.put("devtype", "C");
}
output.collect(key, value);
begin;
-- Figure out the distance to all applicable parcels
create index jobs_devtype_index on jobs using btree ("devtype");
create index parcels_devtype_index on parcels using btree ("devtype");
create temp table distances on commit drop as
select jobs.id as job_id, parcels.id as parcel_id, distance(jobs.the_geom, parcels.the_geom)
from jobs, parcels
where jobs.devtype = parcels.devtype;
-- Find the distance to the closest parcel
create temp table min on commit drop as
select job_id, min(distance) as distance
from distances
group by job_id;
-- Match the job to the closest parcels
create index distances_distance_index on distances using btree ("distance");
create index min_distance_index on min using btree ("distance");
create temp table nearest on commit drop as
select distances.job_id, distances.parcel_id
from distances, min
where distances.job_id = min.job_id
and distances.distance = min.distance;
-- Only use unique job_id's
create index nearest_job_id_index on nearest using btree ("job_id");
create table "jobs_parcels" as
select nearest.job_id, nearest.parcel_id
from nearest
where nearest.parcel_id = (select n.parcel_id from nearest as n where n.job_id = nearest.job_id limit 1);
commit;
insert into parcels values (97123897, ST_GeomFromText('POLYGON((-112.0859375 33.4349975585938,-112.0859375 33.4675445556641,-112.059799194336 33.4675445556641,-112.059799194336 33.4349975585938,-112.0859375 33.4349975585938))', 4326), 'C');
create table output as
select parcels.* from parcels, (select ST_GeomFromText('POLYGON((-112.0859375 33.4349975585938,-112.0859375 33.4675445556641,-112.059799194336 33.4675445556641,-112.059799194336 33.4349975585938,-112.0859375 33.4349975585938))', 4326) as the_geom) as box
where ST_Intersects(parcels.the_geom, box.the_geom);
update parcels set devtype = 'C' where id = 1008130;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment