<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: gis code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 13 Oct 2008 23:11:12 GMT</pubDate>
    <description>DZone Snippets: gis code</description>
    <item>
      <title>Download  coordinate from maproom</title>
      <link>http://snippets.dzone.com/posts/show/4080</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;IFS="&lt;br /&gt;"&lt;br /&gt;for C in Africa Antarctica Asia Australasia Europe North_America South_America&lt;br /&gt;do&lt;br /&gt;	mkdir -p GIS/$C&lt;br /&gt;	wget -O jeter.html -q "http://www.maproom.psu.edu/cgi-bin/dcw/dcwarea.cgi?$C"&lt;br /&gt;	for P in `egrep '^&lt;OPTION' jeter.html | cut -d '&gt;' -f2`&lt;br /&gt;	do&lt;br /&gt;		curl -d "area=$C" -d "country=$P" -o jeter2.html "http://www.maproom.psu.edu/cgi-bin/dcw/dcwcountry0.cgi"&lt;br /&gt;		P2=`grep FORM jeter2.html | grep point10 | tr "&lt;&gt;" "\n\n" | grep count| cut -d ' ' -f4 | cut -d '=' -f2`&lt;br /&gt;		#curl -d "country=$P2" -o jeter3.txt "http://www.maproom.psu.edu/cgi-bin/dcw/point10.cgi"&lt;br /&gt;		wget -O jeter2.html "http://www.maproom.psu.edu/cgi-bin/dcw/point10.cgi?country=$P2"&lt;br /&gt;		P3=`cat  jeter2.html | tr " &gt;" "\n\n" | grep ftp`&lt;br /&gt;		echo "##### $P2 $P3"	&lt;br /&gt;		wget -O jeter3.txt "$P3"&lt;br /&gt;		mv jeter3.txt &gt; GIS/$C/${P2}.js&lt;br /&gt;		sleep 3&lt;br /&gt;	done&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 May 2007 07:29:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4080</guid>
      <author>lindenb (Pierre)</author>
    </item>
    <item>
      <title>Location queries for a model</title>
      <link>http://snippets.dzone.com/posts/show/1906</link>
      <description>// These are class functions which are useful for finding locations in a database &lt;br /&gt;// when PostGIS is not available (when using MySQL for example)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def self.deg2rad(deg)&lt;br /&gt;	(deg * Math::PI / 180)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def self.rad2deg(rad)&lt;br /&gt;	(rad * 180 / Math::PI)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def self.acos(rad)&lt;br /&gt;	Math.atan2(Math.sqrt(1 - rad**2), rad)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def self.distance_in_miles(loc1, loc2)&lt;br /&gt;	lat1 = loc1.latitude&lt;br /&gt;	lon1 = loc1.longitude&lt;br /&gt;	lat2 = loc2.latitude&lt;br /&gt;	lon2 = loc2.longitude&lt;br /&gt;	theta = lon1 - lon2&lt;br /&gt;	&lt;br /&gt;	dist = Math.sin(self.deg2rad(lat1)) * Math.sin(deg2rad(lat2)) &lt;br /&gt;		+ Math.cos(self.deg2rad(lat1)) * Math.cos(self.deg2rad(lat2)) * Math.cos(deg2rad(theta))&lt;br /&gt;	&lt;br /&gt;	dist = self.rad2deg(self.acos(dist))&lt;br /&gt;	&lt;br /&gt;	(dist * 60 * 1.1515).round #distance in miles&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def miles_to(location)&lt;br /&gt;	Location.distance_in_miles(self, location)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def self.locationArea(location, miles)&lt;br /&gt;	radius = miles.to_f&lt;br /&gt;	latR = radius / ((6076 / 5280) * 60)&lt;br /&gt;	lonR = radius / (((Math.cos(location.latitude * Math::PI / 180) * 6076) / 5280) * 60)&lt;br /&gt;	&lt;br /&gt;	{&lt;br /&gt;		:min_latitude =&gt; location.latitude - latR,&lt;br /&gt;		:min_longitude =&gt; location.longitude - lonR,&lt;br /&gt;		:max_latitude =&gt; location.latitude + latR,&lt;br /&gt;		:max_longitude =&gt; location.longitude + lonR&lt;br /&gt;	}&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def self.location_ids_in_range(location, miles)&lt;br /&gt;	la = Location.locationArea(location, miles)&lt;br /&gt;	Location.find(:all,&lt;br /&gt;		:select =&gt; "locations.id",&lt;br /&gt;		:conditions =&gt; ["locations.latitude &lt;= ? and locations.latitude &gt;= ? " + \&lt;br /&gt;			" AND locations.longitude &gt;= ? and locations.longitude &lt;= ?",&lt;br /&gt;			la[:max_latitude], la[:min_latitude], la[:min_longitude], la[:max_longitude]&lt;br /&gt;		]&lt;br /&gt;	).collect { |l| l.id }&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def self.locations_in_range(location, miles)&lt;br /&gt;	la = Location.locationArea(location, miles)&lt;br /&gt;	Location.find(:all,&lt;br /&gt;		:conditions =&gt; ["locations.latitude &lt;= ? and locations.latitude &gt;= ? " + \&lt;br /&gt;			" AND locations.longitude &gt;= ? and locations.longitude &lt;= ?",&lt;br /&gt;			la[:max_latitude], la[:min_latitude], la[:min_longitude], la[:max_longitude]&lt;br /&gt;		]&lt;br /&gt;	)&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Apr 2006 05:46:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1906</guid>
      <author>ajturner (Andrew Turner)</author>
    </item>
    <item>
      <title>Shapefile2KML</title>
      <link>http://snippets.dzone.com/posts/show/893</link>
      <description>&lt;code&gt;&lt;br /&gt;#requires and ArcGIS 9.x licenses&lt;br /&gt;#import standard libraries&lt;br /&gt;import sys, os, win32com.client&lt;br /&gt;&lt;br /&gt;#import the kml library&lt;br /&gt;import pyKML&lt;br /&gt;&lt;br /&gt;#create gp object&lt;br /&gt;gp = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")&lt;br /&gt;&lt;br /&gt;#get the input layer path&lt;br /&gt;layer = "C:/myProjects/CUAHSI/WebServices/NCDC/asos-20051110/asos-20051110.shp" #sys.argv[1]&lt;br /&gt;&lt;br /&gt;#get the lat, lon, name, and id fields&lt;br /&gt;lat_field = "LATITUDE"&lt;br /&gt;lon_field = "LONGITUDE"&lt;br /&gt;elev_field = "STN_ELEV"&lt;br /&gt;name_field = "LOCATION"&lt;br /&gt;id_field = "CALLSIGN"&lt;br /&gt;&lt;br /&gt;#create a cursor on this layer &lt;br /&gt;feats = gp.SearchCursor(layer)&lt;br /&gt;feat = feats.Next()&lt;br /&gt;&lt;br /&gt;#open a kml file to write points into&lt;br /&gt;kml = pyKML.KML_File("C:/myProjects/CUAHSI/WebServices/NCDC/asos-20051110/test.kml")&lt;br /&gt;kml.open_folder("Weather_Stations")&lt;br /&gt;&lt;br /&gt;#loop through features&lt;br /&gt;while feat:&lt;br /&gt;&lt;br /&gt;    shape1 = feat.shape&lt;br /&gt;    part = shape1.GetPart(0)&lt;br /&gt;    &lt;br /&gt;    #get he features attributes&lt;br /&gt;    lat =  part.y&lt;br /&gt;    lon = part.x&lt;br /&gt;    elev = feat.GetValue(elev_field)&lt;br /&gt;    name = feat.GetValue(name_field)&lt;br /&gt;    id = feat.GetValue(id_field)&lt;br /&gt;&lt;br /&gt;    #create a description from the name and id attributes                         &lt;br /&gt;    description = name + "&lt;a href='http://www.nws.noaa.gov/asos/'&gt;http://www.nws.noaa.gov/asos/&lt;/a&gt;"&lt;br /&gt;&lt;br /&gt;    #create a kml placemaker object    &lt;br /&gt;    kml.add_placemarker(lat,lon,0.0,description,id)&lt;br /&gt;                           &lt;br /&gt;    feat = feats.Next()&lt;br /&gt;&lt;br /&gt;#close the folder&lt;br /&gt;kml.close_folder()&lt;br /&gt;&lt;br /&gt;#close file&lt;br /&gt;kml.close()&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 16 Nov 2005 05:39:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/893</guid>
      <author>jgoodall (Jon)</author>
    </item>
  </channel>
</rss>
