Wednesday, October 27, 2010

Monday, October 25, 2010

Java mysql database connectivity

http://www.developer.com/java/data/article.php/3417381/Using-JDBC-with-MySQL-Getting-Started.htm#Discussion%20and%20Sample%20Programs

http://www.kitebird.com/articles/jdbc.html

http://www.kitebird.com/articles/jdbc.html

Sunday, October 24, 2010

Best resource on AIS ever found on internet

Decoding AIS message

Have written an AISparser to automaically decode the AIS data message.

http://www.aishub.net/
AIS is the mariner's most significant development in navigation safety since the introduction of radar. The system was originally developed as a collision avoidance tool to enable commercial vessels to ‘see' each other more clearly in all conditions and improve the helmsman's information about his surrounding environment. AIS does this by continuously transmitting a vessels identity, position, speed and course, along with other relevant information to all other AIS equipped vessels within range. Combined with a shore station, this system also offers port authorities and maritime safety bodies the ability to manage maritime traffic and reduce the hazards of marine navigation.


http://gpsd.berlios.de/AIVDM.html

Thursday, October 21, 2010

web site

http://www.boatingforumz.com/read-AIS-data-encapsulated-NMEA-VDO-sentence-ftopict18911.html

Decode AIS data= AIS parser

!AIVDM,1,1,,A,14eG;o@034o8sd062D,0*7D

In Order:

!AIVDM: The NMEA message type
1 Number of Sentences (some messages need more then one)
1 Sentence Number (1 unless it's a multi-sentence message)
The blank is the Sequential Message ID (for multi-sentence messages)
A The AIS Channel (A or B)
14eG;... The Encoded AIS Data
0* End of Data
7D NMEA Checksum

AIS Data Encoding

In the NMEA encoding for AIS - each ASCII character corresponds to 6 binary bits (unlike normal ASCII which uses 8 bits) so you need to step through each character and subtract 48 from the ASCII - then if it's still a decimal number > 40 subtract another 8 - then convert to binary: this guarantees a 6 bit number. Looking at our data (just the first few characters)

14eG

1 = 000001
4 = 000100
e = 101101
G = 010111
and so on...

The complete data string decoded looks like this when strung back together.
000001 000100 101101 010111 011100 001010 010000 000000 000000 000000 110111 001000 110111 100001 101000 011100 011101 110010 011111 101011 110000 110101 010111 010000 000000 001000 011000 011011

Now you start grabbing sets of bits from this and converting to decimal. Here are the key pieces of information assuming the first character is a '1' (the message type):

MMSI Number - starting from bit 8 for 30 bits
= 010010110101011101110000101001 = 316005417

HDG - bit 128 for 9 bits
COG - bit 116 for 12 bits (and divide by 10)
SOG - bit 50 for 10 bits (and divide by 10)

Lat - bit 89 for 27 bits (a signed binary number, divide by 600000)
Lon - bit 61 for 28 bits (a signed binary number, divide by 600000)


import java.util.StringTokenizer;


public class AISDecoder {

public static void main(String[] args) {
String s = "!AIVDM,1,1,,A,14eG;o@034o8sd062D,0*7D ";
StringTokenizer stok = new StringTokenizer(s, ",");

String tokens[] = new String[stok.countTokens()];
for (int i = 0;i< stok.countTokens()+5;i++) {
tokens[i] = stok.nextToken().trim();
}
//System.out.println(tokens[4]);
String msg = tokens[4];
String binarystr = "";
String full = "";

for (int i = 0; i < msg.length(); i++) {
int j = (int) msg.charAt(i);
//System.out.println(j);
j = j - 48;
//System.out.println(j);
if (j > 40) {
j = j - 8;
}
//System.out.println(j);
//System.out.println();
binarystr = Integer.toBinaryString(j);
int len = binarystr.length();
switch (len) {
case 1:
binarystr = "00000" + binarystr;
break;
case 2:
binarystr = "0000" + binarystr;
break;
case 3:
binarystr = "000" + binarystr;
break;
case 4:
binarystr = "00" + binarystr;
break;
case 5:
binarystr = "0" + binarystr;
break;
case 6:
binarystr = "" + binarystr;
break;
}
// System.out.println(binarystr);
// System.out.println("");
full = full.concat(binarystr).trim();
}
System.out.println(full);
//System.out.println(full.length());
String msgtype = full.substring(0, 6);
System.out.println(msgtype);
System.out.println(Integer.parseInt(msgtype,2));

String repind = full.substring(6, 8);
System.out.println(repind);
System.out.println(Integer.parseInt(repind,2));

String mmsi = full.substring(8, 38);
System.out.println("mm"+mmsi.length());
System.out.println(Integer.parseInt(mmsi,2));

String aisversion = full.substring(38,40);
System.out.println(Integer.parseInt(aisversion,2));

String imonum = full.substring(40,70);
System.out.println(Integer.parseInt(imonum,2));


String lon = full.substring(61, 88);
System.out.println("len" + lon.length());
int lonint = Integer.parseInt(lon,2);
float lonflo = (float)lonint/600000;
System.out.println(lonflo);

String lat = full.substring(89,117);
int latint = Integer.parseInt(lat,2);
float latflo = (float)latint/600000;
System.out.println(latflo);

// String callsign = full.substring(70,112);
// System.out.println(callsign.length());
//System.out.println(Double.parseDouble(ca));

// System.out.println(mmsi);
// System.out.println(Integer.parseInt(mmsi,2));
}
}

Monday, October 18, 2010

PoStGiS

spatial database postGIS
installed on top of Postgresql
http://postgis.refractions.net/download/windows/

NMEA 083 is the format for AIS string.

AIS database design

Figuring our how to install Hsql database
installing the db- embeded java database
this needs knowledge of hibernate, so have to learn hibernate
--------------------------------------------------------------
deadend

Sunday, October 17, 2010

Find out AIS data receiving format

Observe the AIS data receiver and transmission formats.
design AIS data storage database
Finding and longitude from AIS data string.
Try out mouse position tracking from AIS data

Tuesday, October 12, 2010

AIS database design-1


AIS Database Powered by GIS Technology for Maritime Safety and Security


Ziqiang Oua1 c1 and Jianjun Zhua1
a1 (Central South University, P.R. China)

Abstract

The Automatic Identification System (AIS) is an efficient tool to exchange positioning data among participating naval units and land control centres. It was developed primarily as an advanced tool for assistance to sailors during navigation and for the safety of the life at sea. Maritime security has become a major concern for all coastal nations, especially after September 11, 2001. The fundamental requirement is maritime domain awareness via identification, tracking and monitoring of vessels within their waters and this is exactly what an AIS could bring. This paper will be focused on how the AIS-derived information could be used for coastal security, maritime traffic management, vessel tracking and monitoring with the help of GIS technology. The AIS data used in this paper was collected by the Canadian national aerial surveillance program.

Key Words:Automatic Identification System; Geographic Information System; Marine Security; Aerial Surveillance


got an idea of how the AIS really function in nava

Monday, October 11, 2010

Found MapMouseEvent method

getMapPosition

public DirectPosition2D getMapPosition()
Get the position, in map (world) coordinates of this mouse event

Returns:
a new DirectPosition2D object for the world coordinates
//////////////////////////////////////
this should work?

get mouse position

http://docs.geotools.org/stable/javadocs/org/geotools/swing/event/MapMouseEvent.html

Friday, October 8, 2010

offline repository

Maven Alternative

The alternative to using Maven to download and manage jars for you is to manually install them. To start with we will obtain GeoTools from the website:

  1. Download the GeoTools binary release from http://sourceforge.net/projects/geotools/files

  2. Extract the geotools-2.6.0-bin.zip file to C:javageotools-2.6.0 folder.

  3. If you open up the folder and have a look you will see GeoTools and all of the other jars that it uses including those from other libraries such as GeoAPI and JTS.

    ../_images/gtunzipped.jpg
  4. We can now set up GeoTools as a library in NetBeans:

    From the menu bar choose Tools > Libraries to open the Library Manager.

  5. From the Library Manager press the New Library button.

  6. Enter “GeoTools” for the Library Name and press OK

  7. You can now press the Add JAR/Folder button and add in all the jars from C:javaGeoTools-2.7-M2

  8. GeoTools includes a copy of the “EPSG” map projections database; but also allows you to hook up your own copy of the EPSG database as an option. However, only one copy can be used at a time so we will need to remove the following jars from the Library Manager:

  1. GeoTools allows you to work with many different databases; however to make them work you will need to download jdbc drivers from the manufacturer.

    For now remove the following plugins from the Library Manager:

    • gt-arcsde
    • gt-arcsde-common
    • gt-db2
    • gt-jdbc-db2
    • gt-oracle-spatial
    • gt-jdbc-oracle
  2. We are now ready to proceed with creating an example project. Select File > New Project

  3. Choose the default “Java Application”

  4. Fill in “Tutorial” as the project name; and our initial Main class will be called “Quickstart”.

  5. Open up Example in the Projects window, right click on Libraries and select Add Libraries. Choose GeoTools from the Add Library dialog.

  6. Congratulations ! You can now return to Quickstart or any of the other tutorials

Thursday, October 7, 2010

Tried new geotools tutorial

different main method for caching the shape file

        CachingFeatureSource cache = new CachingFeatureSource(featureSource);

added to the quick start

with the
import org.geotools.data.CachingFeatureSource;

Configure and install geotools to my new laptop from beginning

I recently found out these things about maven and Geotools

The GeoTools development community uses the build tool Maven which is integrated into the latest releases of NetBeans.

The advantages of using Maven are:

  • You only download as much of GeoTools as your application requires Jars are downloaded to a single location in your home directory (in a hidden folder called .m2/repository)
  • Source code and javadocs are automatically downloaded and hooked up

Although Maven is a build tool it works by describing the contents of a project. This is a different approach then used by the Make or Ant tools which list the steps required to build.


what is a POM file

Part of the description of a project is the required jars and a repository on the internet where they can be downloaded from. We will be using these facilities to bring GeoTools jars as needed into our project.

The pom.xml file is used to describe the care and feeding of your maven project; we are going to focus on the dependencies needed for your project


PLATFORM LOCAL REPOSITORY
Windows XP: C:\Documents and Settings\Jody\.m2\repository
Windows: C:\Users\Jody\.m2\repository
Linux and Mac: ~/.m2/repository

finally some thing to work with

Bernhard Kastner wrote:

> 1. How do I get the world-coordinates when clicking with the mouse?
> When adding a normal MouseListener, it only returns the coordinates on
> the screen, but I would like to know the position on the map.

[solved]
Using org.geotools.renderer.j2d.GeoMouseEvent.getMapCoordinate();

> 2. How do I change the behaviour of the mouse on a map? When clicking
> and draging the mouse, it generates a zoom-pane with the selected
> area. I want to change this behaviour to pan the map. So, when moving
> the mouse, the map also moves, but doesn't zoom or anything else. Is
> this possible?
>
> And another question: As already mentioned, I'm using the methods as
> in the Spearfish Sample, which uses J2D-renderer. I experienced
> OutOfMemoryExceptions when dealing with larger shapefiles (3x 30 MB).
> Is there a possibility to avoid that?

I would still appreciate some suggestions ;)

Bernhard

Wednesday, October 6, 2010

Learning Java and geo tools documentation

Today i did java to refresh my java knowledge.
8/30 to 1.pm read the book Head first java
afternoon i refer the Geotools documentation.

Monday, October 4, 2010

Initial Presentation- Navy Command Elecronics work shop west wing Rangala

Did a Initial presentation

Finding out how to write a mouse listener in GeoTools.

Displaying a shape file



finally downloaded the jar files necessary for displaying a shape file.

\\\\\\\\\\\\\\\code for display shape file
// docs start source
/*
* GeoTools - The Open Source Java GIS Tookit
* http://geotools.org
*
* (C) 2006-2008, Open Source Geospatial Foundation (OSGeo)
*
* This file is hereby placed into the Public Domain. This means anyone is
* free to do whatever they wish with this file. Use it well and enjoy!
*/
package org.geotools.demo;

import java.io.File;

import org.geotools.data.CachingFeatureSource;
import org.geotools.data.FeatureSource;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;

/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile
* and displays its contents on the screen in a map frame
*
* @source $URL$
*/
public class Quickstart {

/**
* GeoTools Quickstart demo application. Prompts the user for a shapefile
* and displays its contents on the screen in a map frame
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}

FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();

// Create a map context and add our shapefile to it
MapContext map = new DefaultMapContext();
map.setTitle("Quickstart");
map.addLayer(featureSource, null);

// Now display the map
JMapFrame.showMap(map);
}
// docs end main

// docs start cache
/**
* This method demonstrates using a memory-based cache to speed up
* the display (e.g. when zooming in and out).
*
* There is just one line extra compared to the main method, where
* we create an instance of CachingFeatureStore.
*
* @throws Exception
*/
public void usingFeatureCaching() throws Exception {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}

FileDataStore store = FileDataStoreFinder.getDataStore(file);
FeatureSource featureSource = store.getFeatureSource();

CachingFeatureSource cache = new CachingFeatureSource(featureSource);

// Create a map context and add our shapefile to it
MapContext map = new DefaultMapContext();
map.setTitle("Using cached features");
map.addLayer(cache, null);

// Now display the map
JMapFrame.showMap(map);
}
}
// docs end source

///////////////pom file////////

4.0.0
org.geotools.demo
example
jar
1.0-SNAPSHOT
example
http://maven.apache.org

2.6.4



junit
junit
3.8.1
test


org.geotools
gt-main
${geotools.version}


org.geotools
gt-shapefile
${geotools.version}


org.geotools
gt-epsg-hsql
${geotools.version}


org.geotools
gt-swing
${geotools.version}




maven2-repository.dev.java.net
Java.net repository
http://download.java.net/maven/2


osgeo
Open Source Geospatial Foundation Repository
http://download.osgeo.org/webdav/geotools/



/////////////////////////////////////////////