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.