Monday, April 19, 2010

IFile, IFileStore and opening an EditorPart

Eclipse's engines turn around the idea of a project.

If I want to open an Editor on a file, I would have to do:


IFile iFile = myIFile;
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.openEditor(iFile, FormEditor.ID);


apart for the fact that IFile refers on a file inside the project, which makes sense inside eclipse, but perhaps not always in an RCP product basing on eclipse.

So to open an editor on an external (external == wherever in the filesystem != in the eclipse project) file, here is what is possible since 3.3:


File f = new File(path);

IPath ipath = new Path(f.getAbsolutePath());
IFileStore fileLocation = EFS.getLocalFileSystem().getStore(ipath);
FileStoreEditorInput fileStoreEditorInput = new FileStoreEditorInput(
fileLocation);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
page.openEditor(fileStoreEditorInput, FormEditor.ID);

Saturday, April 10, 2010

Grass raster datastore finally in geotools

I finally took the time to get the GRASS raster reader into geotools...

It is started now and available in the unsupported land of the geotools svn:

http://svn.osgeo.org/geotools/trunk/modules/unsupported/grassraster

Gonna be funny see geoserver finally serve grass rasters as udig :)

Wednesday, April 7, 2010

EPL-GPL: the verdict

Some time ago I wrote a post referring to the GPL / EPL licenses incompatibility. To the letter I wrote at that time and sent to both the Eclipse Foundation adn the FSFEurope, I never got and answer from FSFEurope, but I got several directly form the Executive Director of the Eclipse Foundation, Mike Milinkovich, who was very helpful in getting a good picture of what the problems are.

At the time of sending my email, Eclipse Foundation and FSF were discussing the GPL/EPL issue, so I didn't get a direct answer to the questions in the open letter, but now there is a public answer about the issues available:

Here the point of view of the Eclipse Foundation can be found.

And here the public statement of the FSF.

I will definitely not comment here. Wait for you guys in the mailinglists for a nice chat about that.

Friday, March 5, 2010

How to listen to a feature creation by an edit tool

Today Virginie BERRE of Magellium showed a nice way to catch a feature created with the editing tool in udig. Guess I have to post that here in order to remember it myself :)


map.getEditManager().addListener(new IEditManagerListener() {
public void changed(EditManagerEvent event) {
SimpleFeature feature= map.getEditManager().getEditFeature();
if(feature != null) {
FilterFactory factory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
Id uDigfilter = factory.id(Collections.singleton(feature.getIdentifier()));
try {
FeatureCollection collection = dodStore.getFeatures(uDigfilter);

// do something with it

} catch (IOException e) {
e.printStackTrace();
}
}

}

});

Thursday, February 25, 2010

About 7.000.000 and more lidar points, the quest for Powerline extraction and JGrass asking help to Nasa World Wind

Do you know what this is?


More than 7.000.000 of points rendered in JGrass from a las file. Yes, It does look awsome and is well navigable (with enough ram and videocard :)).

How? By putting Nasa World Wind as a plugin into JGrass and tweak a bit the OpenGL rendering through the jogl libraries.

Why? Prototyping around extraction of powerlines.

Want to know more? What happened next?
Well... we were asked to explore a bit with feature extraction from lidar data, starting fromm the most difficult: powerlines.

While prototyping we added some tools to read las files and filter the signals through intensity, density of points, elevation difference with the dtm and things like that. Well the result up to now is pretty nice...

Ok, first let's extract the data inside a polygon... now can you see the powerlines?


Ok, let's change the coloring... no more elevation based, but intensity based:


And here we zoom in and color based on point density (in 3d), now the powerlines are already colored differently from most of the rest.



Some filtering based on intensity, density and elevation difference with the dtm and here we go (it looks empty, but have a closer look):




Let's get back to 2d using a small partial example, how does that look like?



Hmmmm, looks that one of the two is a bit wrongly placed... let's check:




Seems we are right? Check with the aerial photo:



Aha, so we are right...

Well, this is just the first part, but it already look promising.

Looking forward to mature this plugin to get it into the JGrass plugins that are going to be released.

Tuesday, February 2, 2010

L'unità di tutte le scienze è trovata nella geografia.

L'unità di tutte le scienze è trovata nella geografia. Il significato della geografia è che essa presenta la terra come la sede duratura delle occupazioni dell'uomo. (John Dewey).


Alle elementari avevo un maestro che insegnava geografia e che tirava giù una carta geografica del mondo davanti alla lavagna. Avevo un compagno di classe al sesto anno che un giorno ha alzato la mano e ha indicato la costa orientale del Sudamerica; poi ha indicato la costa occidentale dell'Africa e ha chiesto: «Sono state mai unite?». E il maestro ha risposto: «Certo che no, è una cosa ridicola!». Lo studente cominciò a fare uso di droghe e sparì. L'insegnante è diventato consigliere scientifico dell'attuale amministrazione (ndr Bush). (dal film documentario statunitense del 2006 "Una scomoda verità", diretto da Davis Guggenheim).


Nella mia geografia ancora sta scritto che tra Catanzaro e il mare si trovano i Giardini delle Esperidi. (George Robert Gissing, da Sulle rive dello Jonio).


L'arma del giornalista è la penna o la macchina da scrivere. L'arma del giornalista sotto vetro smerigliato è la bacchetta o la carta geografica. (Sergio Saviane).


Lungo la costa dell'Africa del Sud-Ovest, delimitato da montagne di origine vulcanica da una parte e dall'Atlantico dall'altra, si stende uno dei più antichi e selvaggi deserti della terra. I geografi chiamano questa zona la Costa degli Scheletri, perché le sue spiagge sono disseminate dei relitti delle navi che vi hanno fatto naufragi. (Ronald Schiller da "Nel mondo dei diamanti").



La geografia non e' solo una mappa di google o un navigatore GPS. Non e' solo il fascino degli aspetti che rappresentano la terra. Non e' solo!

La geografia unisce tutto in modo coerente, riesce a spiegare fenomeni che regolano continenti e popolazioni intere, e' lo studio antropico delle culture, vicine e lontane. Tutto cio' che internet per certi versi in maniera fuorviante ci ha portato sullo schermo di casa, convincendoci di poter sapere, di potere conoscere tutto nell'attimo di un click.

Eppure non e' cosi'.

Sapere Aude!

Lo studio della geografia e' uno strumento necessario.

Una volta mi hanno raccontato di un ragazzo americano che era convinto, evidentemente educato dalla pubblicita', che le mucche fossero viola. Mi ricordo di avere trovato particolarmente ridicola la storia. Ora mi chiedo cosa potrebbe succedere a noi nel caso in cui andasse persa un disciplina importante come la geografia.

Vogliamo veramente spingere la gia' decadente situazione dell'istruzione fino ad arrivare a privare i giovani di tutti gli strumenti necessari a capire la complessita' che si cela dietro alla nostra terra? Vogliamo veramente privarli degli strumenti necessari a prendere decisioni competitive e allo stesso tempo sostenibili assieme a coloro con i quali condividono lo stesso globo?





Firma la petizione presso il sito
dell'Associazione Italiana Insegnanti Geografia



Insieme a:

Sunday, January 31, 2010

new console language extentions arriving

Not much to say...


# MAPSET= mapsetpath

// print out all available commands and variables
PRINTCOMMANDS

// access the current processing region attributes
echo NORTH
echo SOUTH
echo EAST
echo WEST
echo WERES
echo NSRES
echo ROWS
echo COLS

// or the region itself
echo ACTIVEREGION

// get the coordinate at a given row and col
def coordinate = coordinateFromRowCol(10, 15);
echo coordinate;

// get the nearest row and col to a given coordinate
def rowCol = rowColFromCoordinate(688605.0, 5108595.0);
echo rowCol;

/*
* reading and writing GRASS maps
*/
def grassMapName = "bacino_brenta_pit";

// get the full path of the map
def fullPath = fullMapPath (grassMapName);
echo fullPath;

// read the map
double[][] map = grassMapToMatrix (grassMapName);
// and print the output to console
printMap map

// get the average value
def avg = grassMapMax(grassMapName);
echo avg
// the same can be done for grassMapMin ,grassMapAvg, grassMapModa

// get the value of a grass raster map at a given coordinate
def value = valueOfGrassMapInCoordinate(grassMapName, 688605.0, 5108595.0);
echo value;

// write the matrix read before to a map named aaa
def grassMapToWrite = "aaa";
matrixToGrassMap (grassMapToWrite, map, -9999.0);

// delete the map from disk
deleteGrassMap grassMapToWrite;

// load a map to be viewed
loadGrassMap grassMapName;


/*
* working with vector layers and shapefiles
*/
// get the list of features from a layer
// that is loaded in the current active map
def features = getFeaturesFromLayer("countries");
features.each{ feature ->
// some features can be accessed directly on the feature,
// like area, length or the coordinates of the geometry
// as well as the centroid and the geometry itself
echo feature.area;
echo feature.length;
echo feature.coordinates[0];
echo feature.centroid;
echo feature.getAttribute("FIPS_CNTRY");
}

// the same can be done from a shapefile
def features = getFeaturesFromShapefile("D:\\data\\wb\\countries.shp");
features.each{ feature ->
echo feature.area;
echo feature.length;
echo feature.coordinates[0];
echo feature.centroid;
echo feature.getAttribute("FIPS_CNTRY");
}

// cql filters can be used from layers
def features = getFilteredFeaturesFromLayer("countries",
"INTERSECTS(the_geom, LINESTRING (11 41, 18 41))");
features.each{ feature ->
echo feature.area;
echo feature.length;
echo feature.coordinates[0];
echo feature.centroid;
echo feature.getAttribute("FIPS_CNTRY");
}

// or again from shapefiles
def features = getFilteredFeaturesFromShapefile("D:\\dat\\wb\\countries.shp",
"LONG_NAME == 'Russia'");
features.each{ feature ->
echo feature.area;
echo feature.length;
echo feature.coordinates[0];
echo feature.centroid;
echo feature.getAttribute("FIPS_CNTRY");
}

// statistics can be calculated on fields of the features
// average of the field SQKM
def avg = featuresLayerAvg("countries", "SQKM");
echo avg;
avg = shapefileAvg("D:\\data\\wb\\countries.shp", "SQKM");
echo avg;

// min of the field SQKM
def min = featuresLayerMin("countries", "SQKM");
echo min;
min = shapefileMin("D:\\data\\wb\\countries.shp", "SQKM");
echo min;

// max of the field SQKM
def max = featuresLayerMax("countries", "SQKM");
echo max;
max = shapefileMax("D:\\data\\wb\\countries.shp", "SQKM");
echo max;

// moda of the field SQKM
def moda = shapefileModa("D:\\data\\wb\\countries.shp", "SQKM");
echo moda;
moda = featuresLayerModa("countries", "SQKM");
echo moda;


/*
* DATABASE COMMANDS (assuming table has two fields: id, name)
*/
// define the database connection
# REMOTEDBURL = postgresql:192.168.1.102:5432:dbname:user:passwd

// the table name
def table = 'schema.tablename';

// get the dataset and browse over it
def ds = dataset( table );
ds.each{
// "name" is a db table field name and can be
// used as variable to access the needed value
echo it.id + " " + it.name;
}

// another way is to use select statements
def rows = select ("* from " + table);
rows.each{ row ->
echo row.id + " " + row.name
}

// which can contain also the where clause
def rows1 = select ("* from " + table + " where name = 'coudiness'");
rows1.each{ row ->
echo row.id + " " + row.name;
}

// for counting rows there is
def num = count(table);
echo num;
// on which the where clause also works
def num1 = count( table + " where name = 'coudiness'");
echo num1;

// for eveything else the database instance can be accessed
// and any query can be executed
DB.eachRow("select * from " + table){
echo it.id + " " + it.name;
}


/*
* data import and export
*/
// import an esri ascii grid to grass raster map
importEsriAscii("C:\\TMP\\brenta2.asc", "testascii");

// import a tiff to grass raster map
importTiff("C:\\TMP\\brenta2.tif", "testtiff");

// import grass raster map to an esri ascii grid
exportEsriAscii("bacino_brenta_pit", "C:\\TMP\\brenta2");

// import grass raster map to a tiff
exportTiff("bacino_brenta_pit", "C:\\TMP\\brenta2");

/*
* the mapcalculator
*/
mapcalc {
result "mapcalctest"
function """
if ("bacino_brenta_pit" > 1200,
1.0,
"bacino_brenta_pit" / 2.0)
"""
}