venerdì 8 agosto 2014

How search/and/replace in a file

The need is to change the paths in a text file to adapt the filepaths from a pc to another pc.

To do this the choose is to use the "sed"  command.

After a googling I find this hint:
http://stackoverflow.com/questions/525592/find-and-replace-inside-a-text-file-from-a-bash-command
In it there is this sample:
in the file "/tmp/file.txt" change all occurrence of "abc" to the new string "XYZ"

The start point is this hint

sed -i -e 's/abc/XYZ/g' /tmp/file.txt
 
from here

qgis-server: remove maptip virtual field added to a getfeatureinfo response.

#1:

QGIS-Server add a ridicolous "maptip" attribute to some response of GetFeatureInfo request.
Is quite impossile to understand why it add it.  I almost was not capable to undestand why.
:))
 
I try also to undesrad why some layer yes and some other layer no, but was not capable to undestand this.
I try to ask to the ML of qgis (user and dev), but no response to this requests.
And this is the more clear explanation of what is this MapTIP virtual field added.

SO , I guess the strategy to add that field is quite wrong, infact often add it when not requested.

Perhaps it is useful for the specific qgis-server client, but absolutely unuseful for a standard WMS client.
So the better and rapid solution,
Is remove it and recompile qgis.


To do this:
-----------------------------------------------------------------
Open
QuantumGIS/src/mapserver/qgswmsserver.cpp

around line 1812

comment all this code:

      //add maptip attribute based on html/expression (in case there is no maptip attribute)
//      if ( layer->fieldNameIndex( layer->displayField() ) < 0 )
//      {
//        QString displayField = layer->displayField();
//        if ( !displayField.isEmpty() )
//        {
//          QDomElement maptipElem = infoDocument.createElement( "Attribute" );
//          maptipElem.setAttribute( "name", "maptip" );
//          maptipElem.setAttribute( "value",  QgsExpression::replaceExpressionText( displayField, &feature, layer ) );
//          featureElement.appendChild( maptipElem );
//        }
//      }

Ok, after this, go around line 2906 and comment also this code:

  //add maptip attribute based on html/expression (in case there is no maptip attribute)
//  if ( layer->fieldNameIndex( layer->displayField() ) < 0 )
//  {
//    QString displayField = layer->displayField();
//    if ( !displayField.isEmpty() )
//    {
//      QString fieldTextString = QgsExpression::replaceExpressionText( displayField, feat, layer );
//      QDomElement fieldElem = doc.createElement( "qgs:maptip" );
//      QDomText maptipText = doc.createTextNode( fieldTextString );
//      fieldElem.appendChild( maptipText );
//      typeNameElement.appendChild( fieldElem );
//    }
//  }

And after this you can recompile the qgi happy that the stupid maptip field is no more in the

Et-Voila'.
.

giovedì 7 agosto 2014

How retrieve polygons from a set of lines

The use-case is that the usual  BuildArea don't work because the linea are tto mixed and intersecating each other.

The solution is to noed them before the BuildArea.

So, as example:
this code:

The shapefile with the lines to transform in polygon is named "errbordo.shp"
----------------
.headers on
.timer on

.loadshp errbordo errbordo CP1252 3003 geometry pk_uid auto 2d 1

create table tabella_nodata as select * from errbordo;
select RecoverGeometryColumn('tabella_nodata','geometry',3003,'LINESTRING','XY');
select CreateSpatialIndex( 'tabella_nodata','geometry' );
select AddGeometryColumn( 'tabella_nodata','geometry_noded', 3003, 'MULTILINESTRING','XY' );
select AddGeometryColumn( 'tabella_nodata','geometry_poligono', 3003, 'MULTIPOLYGON','XY' );

update tabella_nodata set geometry_noded = ST_NODE(geometry);

update tabella_nodata set geometry_poligono = ST_Multi(ST_BuildArea(geometry_noded));

the field "geometry_poligono" has the polygon.
----------------

The End.


lunedì 14 luglio 2014

Calculate the mapping between PIXELS and MM in a outline rendering

The problem was:
In qgis the outline was rendered with a 0.26 mm outline.

How much it is in pixels ?

The formulaes are these:

1 meters = 39.37007 inch

1 mm = 39.37007 / 1000 = 0.03937007 inch

0.26 mm = ( 39.37007 / 1000 ) * 0.26mm (the outline)  = 0.01023

If the monitor is at 72dpi:
 72dpi => 0.01023 x 72 = 0.73 pixel width

If the monitor is at 91dpi:
91dpi => 0.01023 x 91 = 0.93 pixel width

Thats all.

mercoledì 18 giugno 2014

How remove a kind of file recursively on Linux

I need to remove all the *.tiff files from a set of folders recursively.
The  most obvious solution
rm -Rf *.tiff
don't work.
:)

This is the solution I find:

find . -name '*.tiff' -exec rm {} \;


giovedì 12 giugno 2014

Using GDAL to add a field to a shapefile and populate it

The need is:

I have a set of shapefile and need to have another copy of them addind a new field and populating it with the filename (without extension it match a code identifier).


The solution was using a shell dos and the ogr2ogr and ogrinfo utility:

This is the code:

I use the gdal batch utility from osgeo4w package.

-----
mkdir destination-folder
for /R D:\temp\temp2\input-folder %%f IN (*.shp) do (
    ogr2ogr D:\temp\temp2\destination-folder\zz_%%~nf_output.shp %%f
    cd D:\temp\temp2\input-folder
    ogrinfo zz_%%~nf_output.shp -sql "ALTER TABLE zz_%%~nf_output ADD COLUMN filename character(128)"
    ogrinfo zz_%%~nf_output.shp -dialect SQLITE -sql "UPDATE zz_%%~nf_output SET filename = '%%~nf'"
    cd ..
)
------

Just an explain of some details:
In the ogrinfo command: in the alter-table sql command the tablename inside the sql command should be equals to the filename of shapefile called externally.
In the ogrinfo command: in the update sql-command  there is the same relation name-table with name shapefile of the alter-table.



lunedì 2 giugno 2014

How find a word

I need to find a word "GAIA_VECTORS_LIST_FAST" but I don't know exactly in what file it can be.

So apply this command in a bash :

find ./  -type f -exec grep "GAIA_VECTORS_LIST_FAST" {} \; -print

et voila.

The response is:

  list = gaiaGetVectorLayersList( handle, NULL, NULL, GAIA_VECTORS_LIST_FAST );
./src/providers/spatialite/qgsspatialiteconnection.cpp

simple and fast.