Please ask before using content from my blog. I usually say yes.



Sunday, July 27, 2008

ArcObjects command to export shapefile to KML

Hello,

It's been more than 6 months since I published anything here. I stopped publishing due to an accident that kept me kinda busy and "locked" me around the house for a while.

Anyway, I started working with ArcObjects and creating scripts and new commands on the ArcGIS platform. ArcObjects is a library that allows users to create their own scripts that can be plugged in ArcGIS applications and offer some new functionality.

ArcObjects is a set of software components that provide the "plumbing" for the arcGIS applications and can be used to customize, extend, or construct GIS applications.
ArcObjects include more than 1200 types of objects that can be used by programmers to write their own customizations. Initially, an object model of this size can seem a little overwhelming, but the objects in arcObjects are structured similar to the applications in ArcGIS Desktop, so programming using ArcObjects is harder until the programmer understands the structure and the relationships between these objects.

I kinda finished my first big program made using ArcObjects. This program I've made is actually a command for ArcMap called Shape2KML, and it does just what the title says: export ArcMap layers to Google Earth KML format.

A number of layers can be selected and exported to KML format. The types of layers this command works with are shapefiles of any kind and raster layers of type jpg and png. I will try to include more types of layers in the future, like ERDAS Imagine .img files, or TIFF.

I used Google Earth KML API for .NET to create the KML file from the gathered data. This API is open source , and it helped me a lot. thanks.

The description of how the application can be used and how it works can be found on my website: http://rotrekking.ro/Shape2KMLHelp/index.html . I know it's not very simple, but it can be used to create what I need very easy , and it includes most of the features I usually use.
Also, I don't know of any KML exporter for ArcMap that exports raster layers to kml format. Mine works pretty well for images, too.

And finally, the application can be obtained , along with the source code, from ESRI Developer Network.
The ones that have an account can use this link: http://arcscripts.esri.com/details.asp?dbid=15698.

Enjoy , and comment my application in any way. I also accept suggestions, if anyone uses this, here or on my email.

Thanks.

Wednesday, October 17, 2007

4. Using data from existing maps. Georeferencing.

Ok , so let's talk about georeferencing existing maps a little.

I am going two use the software I usually use for this purpose: Global Mapper.
It's a commercial software (sorry, but it's the easiest one for any kind of maps, I will explain why) . Just get a demo. Maybe I will show other methods some other time.

So, what I usually have is a raster map. That actually is an JPEG or TIFF image that represents some map . It does not matter if the image is a scan of a paper map, a digital map found on the internet or any other map from any other source. All it matters is that this map needs to have some well known points.

The example I will show is made using the coordinate grid (this is a GPS calibrated map) , but you can use mountain peaks or any other elements that can be considered points and have known coordinates.

Foe example, on a mountain map, you have three or four GPS measurements from 3-4 different peaks. These can be used to georeference a map of that mountain. It will not be very accurate, though.

So, let's start.
The procedure goes like this:
-using the points you have, get the coordinates of the corners.
-using the coordinates of the corners, georeference the image in any other software. Most software need image corner coordinates, usually NW and SE. Google Earth, GPSTrackMaker, etc use this method, So I use GlobalMapper to get these.

1.Open Global Mapper, and choose "Open Your own data files"

I chose as an example a map of the Tatra mountains, found here.
I downloaded all the pieces and stitched them together using imagemagick
and the montage command.
So ,

1: Open your own data files.
2:Choose your map (image) and click open.
3:Choose Yes (Manually rectify the image).
4:You have to find some known points. In my case, the known points are intersections of the grid lines. Choose at least three points for an acceptable rectification.
OT: there are four types of rectifications: Linear (2 points), affine (3 points), polynomial (4 points) and triangulation (8 points). Read more. Global mapper selects the best option. 3-4 points is usually OK for showing the map in Google Earth and using it for touristic purposes, I had maps rectified with three.

5:Insert the latitude and longitude for each point and click "Add GCP to list"
6:When you have enough points, click OK.
Now you have a georeferenced image (map) in your workspace. But you need this in some tool like Google Earth or GPSTrackMaker to find the locations you need and make tracks on it for later transferring to the GPS unit.
To get the image georeferenced in Google Earth, for example , you need the corners coordinates (NW and SE).

So, let's go to 7:
7:Pick the Digitizer tool
8:Right Click exactly in the NW corner of the image
Choose "Create new Point/Text feature at specified location.
You will repeat this later for the SE corner.
9:Now you get a window like this:
Copy the first coordinate (if you are in the NW corner latitude is North and Longitude is W)
10.Open Google Earth , click Add>Image Overlay
Or ctrl+shift+o , for that purpose
Choose your image.
11:You get an image properties window. you have to paste the coordinates from Global Mapper for all of the four directions: North, West, South ,East. You need to create two points in Global mapper for this, and copy two coordinates from each point.
Copy each coordinate from Global Mapper and paste it into Google Earth at the correct side. Google Earth will automagically convert the coordinates to its format and rectify the image.
12:That's it. Click OK , and let's see.
Find a known spot on the image. I chose this lake, for example.
Drag the slider at the left (opacity) to the left until you see the Google Earth imagery underneath.
13:If the rectification is correct, the image overlay is almost perfectly layered over the satellite imagery. Like this:
Ok, this is about it. Once you georeferenced a map in global Mapper you can save this as a GEOTIFF file for later usage.

Using the image overlay you can find points of need, you can create placemarks, tracks or anything else you might need in Google Earth.
For example, you can create a track that follows a certain path , and upload it to your GPS later to use it in the field:

Ok, so this is kind of it.

Enjoy georeferencing your own maps, or maps you find on the internet that have geographic coordinates on them.

Matei

Sunday, September 16, 2007

3.Getting the data from the web. Travel sites and searching.

I covered getting data from the Google Earth community in a single post because that is the main way of finding geographic locations . But, usually, it's not nearly as much as it is needed. So you need some other sources for data.

These sources can be anywhere on the web, and aren't always the same. For example, a very good source for getting GPS data for mountains in Romania is alpinet.org . In Czech Republic I found lots of data about hotels and such on mapy.cz .

Every country has specific sites with geographic locations. I will try to cover some of the international ones.

To get a location in Google Earth, you need to find its coordinates (latitude and longitude) an a format Google Earth supports:
Degrees minutes seconds, with the hemisphere, like : 49°30'00" N 20°4'10"E
Degrees minutes seconds with a sign (positive is for Northerh(lat) and Eastern(lon) hemispheres, negative is for Southern(lat) and Western(lon) hemispheres ) like: -49°30'00" 20°4'10"
Decimal degrees. In this notation , every degree has decimals, like: -49.5 20.0694444444
...and more. just paste in the search box and see if Google Earth flies there :)

PS : Latitude comes before longitude on most devices and maps.

So, to the DATA!!

Wikipedia is the biggest online encyclopedia . But a kinda new feature to wikipedia is the Geographical Coordinates Project . This allows users to add geographical coordinates to articles.

For example, I need information about the Gerlach peak in Slovakia. I look for it on the wiki, and I see the coordinates in the article.
I need these in Google Earth. When i click on them , wiki takes me to an extensive page with different representations of the coordinates. now, either I copy them and search in Google Earth, or I search through the links for the direct Googlle Earth link.
Either way, Google Earth centers on the location and creates a temporary point marked with a cross. Like i did with a community point, I add this to my places and I edit its description, title and icon accordingly.


Ok, keep this location in mind. Let's explore some other options.

Down in the wiki page there are lots of options to look at the location. but you already know the location, so what else can be interesting?
Well, there are some things. For example, maybe you want to see what happens nearby , or get coordinates for other nearby places. I only list useful options here, the rest of them are more or less useless because of very little info or clumsy interfaces.
You have these options:
-view nearby photos on Flickr
This is highly unuseful, because Yahoo! maps (which is used by Flickr) doesn't show you the coordinates of a location (photo, in this case). So you cannot get data easily from here.Maybe I will cover that sometime.
-view nearby places on GeoUrl
This is excellent as it provides locations of nearby places. Choose a location, click recenter, copy the coordinates, paste in Google Earth, get a new spot. Simple as that.
-loc.ali.ze.us provides a nice interface to flickr photos , and combines Flickr, adress search (in some areas) and Google Maps. Better than the Flickr option. Also, clicking on a photo gives you the exact coordinates, which is excellent. Thumbs up for this. you can find coordinates by adress or by tags, and look at the photos there.
-wikimapia provides an interface for viewing user added data in the form of polygons+description. Find narby locations bu clicking on polygons. Coordinates are shown in the upper right corner of the screen. While you are there, just add a new description or complete an existing one if you can. This is how these work.

Ok, that's about it with wikipedia and the other related sites. You can use any of these presented sites to get information on any location.

Let us direct our attention to a new candidate, Yahoo! travel and Yahoo! trip Planner . This more like a "HOW NOT TO" presentation.

So, I go to Yahoo!travel and search for Prague. Or anything else , for that matter.


First impression is excellent. A lot of places, nicely categorized. Ok, so let's click one.


I clicked the most important one, and I started searching for coordinates....nope. Map.....nope. Oh, there's a map link up there. I'll click it.


The map link is an "interactive" map for the location, like any Yahoo! map this is awully SLOW and totally non-interactive. Not even zooming with mouse scroll, clear zoom levels, etc , so it's very hard to use.

Ok, I'll pass on this and go to yahoo!trips.
I had more luck here because I actually could use something.

First, I search for Prague (again) , and I find a lot of user-posted trips. Again , I try the map view and I get no coordinates. But, there is a simple way to get the coordinates.
Find the place you want in the trip in the "Schedule View" and click on "Map" if this exists:


You will see a map centered on the place . Check the Adress Bar, and find the coordinates, as highlighted :Get in google Earth , and paste them in the search box. Latitude FIRST, longitude AFTER. The Geographic coordinate representation is defined in this way, only Yahoo! is upside down .They are in reversed order on Yahoo! trip planner. Click Search. Google Earth will center on the place:

Again, save the place to "My Places" and add the description and name from Yahoo to it.

Unesco World Heritage is another good idea if you are looking for monuments. If you want to find an important monument, just get it from the list there. Every site has attached coordinates that you can paste and find in Google Earth. It's quite simple and fast.

Next, Google is your friend. If nothing else works, Google it :


Pasting the highlighted coordinates in Google Earth will take you to the center of the lake :)

Getting the data from the web is like a full time job: you never know where your work takes you. So, start digging!

3.Getting the data from the web. The Google Earth Community

I had to split this third chapter in more parts because it's a lot of information. So, in this post I will focus on working with geographic data in Google Earth , and using data provided by the community.

First of all, some history. Google Earth was not created by Google (in fact , Google bought everything and created nothing) , but was purchased from a company called Keyhole inc which was transformed in Google Earth and offered free in a short notice.Check out the old site of keyhole to see it (click any 2003-2004 link there).
The remainders from the keyhole company are the terms of KML (Keyhole Markup Language) and the community, which has its HQ at http://bbs.keyhole.com .

KML is a special XML based language for managing the display of 3d geospatial data in applications. Usually , it was offered to be used with Keyhole software, but was widely adopted and there is lots of software (Flickr, NASA World Wind, GPSTrackMaker, etc) that can interpret and use KML files.
A KML file uses special types of objects for displaying data:
-a Placemark is the equivalent of a waypoint, a point containing a location, a title, description and an icon
-a path is a list of interconnected lines that unite points
-a polygon is a closed shape with a finite number of sides
-a image can be laid over the satellite imaging , and it's called an image overlay

Users create KML files and post them in the KML community . This is where we will search first. Chances are, someone has already created the tour we are looking for.

So, go to bbs.keyhole.com and type what you are looking for.In my example, I want information about Prague. I get a lot of information, but I get a very relevant post.
There are some guys there that just do travel guides. Check this one out: http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/194963/an/0/page/0#194963 and see how much work this guy put into these guides for cities around the world.

Ok, so after clicking View in Google Earth , I get the file in Google Earth and I can play with it.
Like this file, KML files usually have a set of layers you can choose from. Choose only the relevant information, and delete unneeded information. You ca use all of this, but public transport information in this one is simply overwhelming. Maybe if I had a PDA...
You can see the monuments of Prague. These are Placemarks. You can also see the coloured lines in the Prague Walks layer, which are paths (LineStrings) . This file also contains 3d models, but we are currently not interested in that, although it adds visual impact to it :).

After messing around with KML fles, I usually save them layer by layer under relevant names, so I can open the one I need simply with double clicking on it. Also, when choosing "Save As" use the simple KML format instead of the archived KMZ format (zipped KML), because KML is more compatible.

Ok, besides this, you have other methods of getting data in Google Earth.
The most important method of getting data are the integrated layers in Google Earth. You can find these in the sidebar, at the Layers section.


The most important layers are:
Google Earth Community - info gathered automatically from the forum I talked about and added in Google Earth. You can recognize them by blus "I"-s (information).
Geographic Web - contains photos placed on the map from Panoramio , articles from Wikipedia (talk about that later) and travel information
Lodging, roads , dining , shopping, traffic and other layers work only on US territory because they are not maintained by a community. So , these first two are what we need.

So, what do you do with this layers?
First, find something you are interested in.

Right click it, click "Save to my Places".
Find it in My places, and click Properties for it.
Change the caption and the icon as you wish, to make it different from other Google earth Layers , to know it's yours.
So, you found a new place.
It's a good idea to choose custom icons for every type of content. Similar places should have similar icons.
Also, it's a good idea to organize your places by folders. Churches, castles, campings,restaurants, hostels,etc.
For example, I created myself a campings layer:

Another method of finding relevant information is Searching for it within Google Earth.
For example, Searching for Camping in Prague:

Make sure to browse all the pages with Search Results. Google Earth only shows 10 Search Results per page. Look in the Search Results tab and check every page of results. You can also see them all at once by checking them there.

Using Search results is the same as using the other info. you right click> Save to My places and change the caption and the icon. Simple as that.

!!Don't forget to save My Places when you are finished, give it a nice name!!

Notes on Google Earth Community:
Not Everything you find is accurate. Check the description, and estimate the correctness of the information before using it.
Panoramio Pictures are usually off-site. There are very few people that actually put GPS coordinates in the corresponding fields for the pictures. Finding GPS coordinates for a picture is not the easiest job. I will show that to you in the last chapter. Anyway, most people just click on the map where they think and place the picture.
Usually, if there are more pictures of the same place in a spot, it should be correct. But there are cases when the first picture was wrong, and everyone got the location from this picture.
use the Terrain Layer and close-in on the spot. Usually you can figure out if it is correct or not.


Well, that's about all about Google Earth and the possibilities of finding locations using it.
Enjoy.

Saturday, September 15, 2007

2. Satellite navigation (GPS technology).

Well, I have to write at least 3 articles per day to finish this one before I go.

So , let's move on with GPS navigation.

GPS (or Global positioning System) is a system that uses satellites to find your position on Earth.

A GPS receiver calculates its position by measuring the distance between itself and three or more GPS satellites. Measuring the time delay between transmission and reception of each GPS microwave signal gives the distance to each satellite, since the signal travels at a known speed. These signals also carry information about the satellites' location and general system health (known as almanac and ephemeris). By determining the position of, and distance to, at least three satellites, the receiver can compute its position using trilateration. Receivers typically do not have perfectly accurate clocks and therefore track one or more additional satellites to correct the receiver's clock error. (thanks wiki, I couldn't have done it better :)

Basically, and graphically, the system works like this:
The location of all points with equal distance to a certain point in space (the satellite) is a sphere.
Sat1+Sat3, the intersection of 2 spheres defines a circle.
Add Sat2 , and you've got 2 possible points.
One of this points is on Earth, one usually isn't. The bogus point is eliminated either by choosing locally or by adding more measurements.
This is a highly simplified idea about how GPS works, check the link for more.

The United States Department of Defense programmed the system using an initial constellation of 24 satellites. More were added.

I consider no need to further insist on the subject, so I will jump to GPS devices. What do you actually need for the trip?

First, there are some issues you would like to consider:
-do you or don't you have a car
-you do or you don't make trips on bad weather
-the duration of your trip
-the extra options you need
-the characteristics of the terrain

Some examples:
Fujitsu Pocket Loox N100
This one is a small , simple PDA + Navigation Device with an excellent design. Wonderful choice for a car trip in urban areas.
Rocks:
-nice design, good screen
-integrated GPS chip
-other useful PDA functions in a small package
-one of my friends works for Navigon, so you sponsor him :)):)):))
Sucks:
-battery life. if you use it in the car, ok. If not, get it out of your mind.
-software. It's built for navigating, and it will take you there. But logging, transferring data and other stuff is a pain with PDA devices.
-durability is a pain with PDA-s, you drop it and it's over.

Any PDA is about the same : baterry life about 3-6 hrs with GPS, hard to transfer logs and data (I mean not hard, but software is mainly built for the Garmin or NMEA protocols)

Garmin Etrex Vista HCX
This is indeed a travelling device built for trekkers or globetrotters because of its advanced facilites:
-excellent battery life (20+ hrs)
-good coverage thanks to high sensitivity receivers
-color screen
-water resistant , shockproof,etc
-well-known protocol implemented in all GPS-related software
Sucks:
it's not made for car travelling, so it's expensive to get it to show routes and directions (you have to buy CityNavigator)

Garmin Forerunner 305
Or any watch with GPS :) Try Suunto X9 if it fits you.
Rocks:
-very small , useful if you run, bike or do some kind of sport that requires your hands free
-garmin interface to transfer data (I do not know how or if this works)
Sucks:
-limited battery life, with non-replaceable battery
-very limited in navigation

These are just examples of devices. I will present the next chapters with a Garmin device in mind, and I use an old Etrex Venture that does the job nicely and it's not anywhere as expensive as the new devices out there. Which proves my point, any $100 GPS device will do, as long as it's made by Garmin , Magellan or Lowrance and it can communicate with a PC.

Ok, and finally , some GPS terms:
Accuracy - the surface within which the position error is :) . So, an accuracy of 10m means you are a max of 10m away from the point in any direction. GPS accuracy is about 15m without fixed stations.

Waypoint - a set of coordinates that identifies a location on a GPS device. A waypoint has a name and a location, and it can optionally have an icon or a description...

Tracklog or track - the line that corresponds to your movement recorded by the GPS

Route
- A route is a collection of waypoints that are related in a way that permits you to use them to follow a prescribed course. Basically, it's a list of waypoints put together that you follow in a specified order. In auto navigation, a route is a series of turns to get somewhere, but we do not need that definition...

GPS fix - a GPS fix is the procedure of getting the initial information from the satellites to get a position.

Maybe I missed some terms that I will use, I will explain them later...maybe.

1. About maps and places - introduction to cartography and geographic locations.

Well, as I was saying, I'll dig right into it.

Everyone knows what a map is. Like , that piece of paper you take with you on a journey to look on it for directions. :D

Well, I don't think that's a good definition. A map is a simplified , symbolic representation of a terrestrial surface in a reduced size. From the visual point of view a map is a two-dimensional representation of an area.

Simple as that.

Now , let's talk about places for a while, then talk about some "features" of maps.

People felt the need to be able to describe a specific, unique location on Earth using a simple way that everyone can understand. So, the Geographic Coordinate System was born. Well...sort of.

So, basically, every single point on Earth can be determined by three exact coordinates. These coordinates are specific to that point, and two points with the same coordinates do not exist.

Latitude, usually denoted symbolically by the Greek letter phi, \phi\,\!, gives the location of a place on Earth north or south of the equator. Lines of Latitude are the horizontal lines shown running east-to-west on maps. Technically, Latitude is an angular measurement in degrees (marked with °) ranging from 0° at the Equator (low latitude) to 90° at the poles (90° N for the North Pole or 90° S for the South Pole; high latitude).

Longitude is the east-west geographic coordinate measurement most commonly utilized in cartography and global navigation. It is sometimes denoted by the Greek letter λ (lambda)
and it represents the angle between the plan of the Prime Meridian (line that unites the poles passing through Greenwich, England) and the plan of the local meridian (line that unites the poles passing through our location.

Altitude is the difference of elevation between our location and a reference level. Usually, the mean sea level is taken as a reference.

A graphic representation of the coordinates:

An approximate placing of the continents relating to their coordinates:

The Shape of the Earth is an irregular shape, so , to represent this mathematically, one needs to find a regular shape . The regular shape that is closest to the real shape of the Earth is an ellipsoid . An ellipsoid that approximates the shape of the Earth is called a reference ellipsoid. the coordinates that you find for a location are relative to the reference ellipsoid, so, using different reference ellipsoids for the same place, you can get different coordinates (though the difference is insignificant) .

Okay , now about map projections :
A map projection is any method used in cartography (mapmaking) to represent the two-dimensional curved surface of the earth or other body on a plane. The term "projection" here refers to any function defined on the earth's surface and with values on the plane, and not necessarily a geometric projection. Flat maps could not exist without map projections, because a sphere cannot be laid flat over a plane without distortions.

The idea of "projecting" presumes finding a surface that CAN be laid flat over a plane without distortions called a developable surface. The cylinder, cone and of course the plane are all developable surfaces. The sphere and ellipsoid are not developable surfaces. Any projection that attempts to project a sphere (or an ellipsoid) on a flat sheet will have to distort the image (similar to the impossibility of making a flat sheet from an orange peel).

Check the USGS site for more info on projections. The main idea is that data is lost in more than one way:
- by approximating the real Earth surface
- by distorting the surface when creating a projection

The projection is used in everything from paper maps , atlases to digital maps or Satellite imaging software like Google Earth. This is the main reason why getting data from multiple sources (maybe with different projections) can create problems when overlapping.

There is one more thing that needs attention: the scale of a map . The scale represents the ratio between a single unit of distance on the map and the corresponding distance on the ground. The larger the scale, the more accurate the representation. For example, let's consider a distance of 0.1 mm. If I have a map with a 1:500000 scale , this distance will correspond to 50000 mm , or 50 meters. On a larger scale map, let's say 1:10000 , this will correspond to 1 meter. So, visually placing a point on the map will be more accurate if you get a larger scale map.

That is about everything that someone needs to know to be able to create a "virtual trip" using the technology I talked about in the presentation.

We'll see about GlobalPositioningSystem Technology and measuring coordinates using satellites later.
enjoy.

Friday, September 14, 2007

Virtual (planning for real) travelling

Well, I thought about writing this for some time because it was just too much to present at once.

So, you decided to go on the trip of your life. Well, maybe not the trip of your life, maybe just a simple trip in a foreign place.

But, if you are like me, you don't like organized trips. Like, you just put the money on the table, and WE will take you there and show you what WE want YOU to see. i am sure you have seen this in travel offices (things like "5 european Capitals in 10 days" "Italy in 5 nights" "The riviera in 3 and a half days" "Everything about europe in 12 days", etc, bla bla)

So maybe you do not want to see what everyone else sees, and you want to organize on your own.
The next series of articles will cover the VIRTUAL planning for the real deal. i will focus on my trip in Czech Republic , Southern Poland and Slovakia to present you the way I prepare a trip to a totally new location using available technology.

Ok , what WILL be here:
-free and open source software that does the thing (I never pay for my software)
-Navigating using GPS and transferring data to and from the GPS unit
-using available paper maps and scanned maps to add new data
-using satellite images to get data
-using web information to get the data
-integrating all these
-keeping track of your photos' locations (digital cameras only)

what WON't be here
-super duper magical do-it-all $100 software
-Micro$hit products
-extraordinary gadgets that take pictures while tracking GPS and sending the data home through 3G mobile connection . I will explain why this is not reliable.
-keeping the data updated in real time (again, maybe I'll explaiin...)

I will split this in the following:
Part I - Before you go
1. About maps and places - introduction to cartography and geographic locations.
2. Satellite navigation (GPS technology).
3.Getting the data from the web.
4.Obtaining data from existing maps.
5.Integrating the data
6.Transferring the data

Part 2 - when you are there
1.Remember your tracks
2.Synchronize images with your tracks

Part 3 - After you come
1.Publishing your images
2.Using your saved data
3.Show others where you've been

Well, that's it. Part 1 will be up by Sunday, I hope.
Parts 2 and 3 after I come back, in 30 Sept - 1 Oct.

What you need to do what is presented here (tools I use):
Google Earth
GPSTrackMaker free

A GPS Device

A GPS Data Cable
Internet connection (I assume you've got it, cause you are reading this)
Digital camera
And a nice travel guide is always a welcome addition, but optional

Well, I'll start tommorow, hope someone will enjoy this.
Good night :)