воскресенье, 24 августа 2014 г.

Rotation text in line's start point by attribute

I needed to create SLD style for lines with text rotation on angle equals line azimuth in start point of line. Like this:

Data

My table creation script:

CREATE TABLE annotations
(
  gid serial NOT NULL,
  annotation character varying(250),
  the_geom geometry,
  angle character varying(20) DEFAULT 0,
  CONSTRAINT annotations_pkey PRIMARY KEY (gid),
  CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2),
  CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 4326)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE annotations
  OWNER TO postgres;

"angle" field - contains line azimuth, to calculate it i use trigger:

CREATE TRIGGER set_angle
  BEFORE INSERT OR UPDATE
  ON annotations
  FOR EACH ROW
  EXECUTE PROCEDURE setangle();

And function:

CREATE OR REPLACE FUNCTION setangle()
  RETURNS trigger AS
$BODY$
BEGIN
   NEW.angle := degrees(
                             ST_Azimuth(
                                ST_Transform(ST_StartPoint(NEW.the_geom),900913)
                              , ST_Transform(ST_EndPoint(NEW.the_geom),900913)
                             )
                          ) - 90;
   RETURN NEW;
END
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION setangle()
  OWNER TO postgres;

As you can notice my table SRID=4326, but in calculation points transform into SRID=900913. It's becouse my application map projection is EPSG:900913. If do not transform point to projection what you will show this table you get difference between line azimuth and angle field value:

Style

Here is my SLD style:



  
    Annotatioans
    
      Annotations
      Annotations white text
      
              
        
          
            
              the_geom
            
          
          
           
             Arial
             fontSize
             normal
             bold
           
          
           
             
               0.0
               0.5
             
             
               0
               5
             
             
              rotationAngle
             
           
          
          
            1
            
              #000000
            
          
          
            #FFFFFF
          
          10
          yes
        
        
          
            #000000
          
        
      
    
  
 

Main part here is Rotation block:


  rotationAngle


четверг, 12 июня 2014 г.

Some sld styles.


Empty star with default marks

For this needed create three point symbolizers with star mark.


    
     
      
       star
       
        #000000
       
      
      18
     
    
    
     
      
       star
       
        #FF0000
       
      
      16
     
    
    
     
      
       star
       
        #FFFFFF
       
      
      10
     
    

All three point symbolizers pretty same, just difference in size and color. But make sure that you put a smallest makr on the top and biggest on down.

Result:


Double dashed line

It's a line dashed with two vertical lines. For this we a needed create three line symbolizers. One with line and two with vertline marks.


    
     
      #00FF00
     
    
    
     
      
       
        
         shape://vertline
         
          #00FF00
          1
         
        
        10
       
      
      10 30
     
    
    
     
      
       
        
         shape://vertline
         
          #00FF00
          1
         
        
        10
       
      
      10 30
      5
     
    

My vertlines is a 1 pixel in width and 10 pixels in lenght. Parameter stroke-dasharray set a distance bitween marks, in my case 30 pixels. Im not sure that clearly know what meen first number 10. Second mark same but with stroke-dashoffset, this paremeter make a offset from the beginning of the line.


Result:

воскресенье, 6 апреля 2014 г.

Simple WMS server using MapServer.

WMS Server

In last time i was instaled a Mapserver+nginx and show a wms layer in browser. Now i want to make a wms server. For this just needed make a correct map file. But before for make sure that MapServer installed correctly run this command in console:

  $ ./mapserv -v 

Output:

    MapServer version x.x.x OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF OUTPUT=SVG SUPPORTS=PROJ
    SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER INPUT=JPEG 
    INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE DEBUG=MSDEBUG

If SUPPORTS=WMS_SERVER is here - go ahead.

1.WMS Server map file:

MAP
  NAME "Simple map"
  # Map image size
  SIZE 256 256
  UNITS METERS
  CONFIG PROJ_LIB "/usr/share/proj/" #Path to PROJ lib if needed
  SHAPEPATH "/srv/www/maps/shp"  #Path to shape files
  EXTENT 60.4 56.7 60.7 56.9

  #Output projection
  PROJECTION
   "proj=latlong"
   "ellps=WGS84"
   "datum=WGS84"
  END

  # Background color for the map canvas -- change as desired
  IMAGECOLOR 255 255 255
  IMAGEQUALITY 95
  IMAGETYPE png

  #Output file format
  OUTPUTFORMAT
    NAME          "png"
    EXTENSION     "png"
    MIMETYPE      "image/png"
    DRIVER         AGG/PNG
    IMAGEMODE      RGBA
    FORMATOPTION  "INTERLACE=OFF"
  END
   
  # Legend
  LEGEND
    IMAGECOLOR 255 255 255
    STATUS ON
    KEYSIZE 18 12
    LABEL
      TYPE BITMAP
      SIZE MEDIUM
      COLOR 0 0 89
    END
  END


  WEB
    # Set IMAGEPATH to the path where MapServer should
    # write its output.
    IMAGEPATH '/tmp/'

    # Set IMAGEURL to the url that points to IMAGEPATH
    # as defined in your web server configuration
    IMAGEURL '/tmp/'

    # WMS server settings
    METADATA
      'ows_title'          'Simple map'
       ows_onlineresource  'http://MyHost/map/?map=/srv/www/maps/rew.map&'
      "wms_srs"            "EPSG:4326 EPSG:3857"
      "wms_abstract"       "atlands demo WMS"
      "wms_enable_request" "*"
      "wms_encoding"       "utf-8"
    END

    # Template and header/footer settings
    TEMPLATE 'fooOnlyForWMSGetFeatureInfo'
  END

  LAYER
    NAME 'test'
    TYPE POLYGON
    DUMP true
    TEMPLATE fooOnlyForWMSGetFeatureInfo
   #EXTENT 34.59 49.58 34.63 49.6
 DATA my
    METADATA
      'ows_title' 'test'
      wms_srs "EPSG:4326"
    END
    STATUS OFF
    TRANSPARENCY 100

    #Layer projection
    PROJECTION
        "proj=latlong"
 "ellps=WGS84"
 "datum=WGS84"
    END
    CLASS
       NAME 'test' 
       STYLE
         WIDTH 0.91 
         OUTLINECOLOR 0 0 0
         COLOR 214 205 104
       END
    END
  END
END

You can use another projection defenition:

  PROJECTION
    "init=epsg:4326"
  END
But i it evoke an error:
  msProcessProjection(): Projection library error. no system list, errno: 13
For TEMPLATE block using for GetFeatureInfo(). You can find template samples here and extract tamplates,symbols,images and fonts folders into map files directory.

You can try generate a map file using a MapManager.

Check what we have:

   http://MyHost/map/?map=/srv/www/maps/rew.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilitiess

In answer you get a xml file with you wms server settings.

2.Client side

On client side i have a application useing Leaflet so i just add a new layer:

   var wms_server = "http://MyHost/map/?map=/srv/www/maps/rew.map&"
   var NewLayer = new L.tileLayer.wms(wms_server, {
     layers: 'limite',
     format: 'image/png',
     transparent: true,
     srs:"EPSG:4326"
   });
   map.addLayer(NewLayer);

Used materials:
1. www.http://gis-lab.info/qa/mapserver-wms.html
2. www.http://en.it-usenet.org/thread/12216/6154/
3. www.http://www.cybervox.ru/wiki/Docs/GIS/Mapserver
4. www.http://profmarcello.blogspot.ru/2013/06/configuracao-de-layers-wms-do-mapserver.html


понедельник, 4 ноября 2013 г.

Ошибка "Библиотека не зарегистрирована" в ИнГео.

Решение

1.Включить VBScript (команды для 64 битной системы):

Нажмите кнопку Пуск, выберите пункт выполнить, введите cmdи нажмите кнопку ОК.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\vbscript.dllи нажмите клавишу ВВОД.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\jscript.dllи нажмите клавишу ВВОД.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\dispex.dllи нажмите клавишу ВВОД.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\scrobj.dllи нажмите клавишу ВВОД.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\scrrun.dllи нажмите клавишу ВВОД.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\wshext.dllи нажмите клавишу ВВОД.
Введите %systemroot%\syswow64\regsvr32 %systemroot%\syswow64\wshom.ocxи нажмите клавишу ВВОД.

Листинг взят с сайте Майкрософта.
Мне это не помогло.

2.Запуск ИнГео с правами Администратора:

Как ни странно это решило проблему.


среда, 2 октября 2013 г.

Insert Shape file into MS SQL-Server data base.

It's how to use ogr2ogr to insert Shape file into MS SQL-Server data base.
ogr2ogr -overwrite -f MSSQLSpatial "MSSQL:server=MY-PC-NAME;database=mydatabase;trusted_connection=yes" "D:\data\test_shape.shp"
It's create or overwrite table with name - test_shape.

четверг, 18 июля 2013 г.

Install LifeRay 6.1 on Ubuntu and CentOS

Today i will install LifeRay 6.1 GA2 on Ubuntu 13.04 with 1Gb memory.

1. Installing.
At first create new user for Liferay:

sudo adduser --home /home/liferay liferay
Install Java:

sudo apt-get install default-jre
For me it was installed into /usr/lib/jvm/java-7-openjdk-amd64
On CentOS path was:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64
Get a LifeRay:

http://sourceforge.net/projects/lportal/files/Liferay%20Portal/6.1.1%20GA2/liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip
unzip liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip -d /home/liferay
Change user to liferay and go to Liferay folder. There i have a problem becouse when i try to start Tomcat it was not work. So all operations i do as administrator.

2. Tomcat configuration.
How we need to set JAVA_HOME variable. And we do it in bash. Go to file /etc/bash.bashrc and add:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
For CentOS JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
Next you need give a permissions to Tomcat log file. Only heavy artillery helps me:

chmod 777 /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/catalina.out
Okey, now you can start LifeRay

sh /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh
In console you'll get list of variables. And when in catalina.log appears line
INFO: Server startup in 24802 ms
server is start.

3. Add Liferay in autoload
At first create script /etc/init.d/liferay6

#!/bin/bash
# LifeRay Startup Service script v1.0 by Faraz Haider 6 May 2012
# acts as startup service script for LifeRay Portal.
# USAGE: start|stop|status|logs
#
case "$1" in
start)
echo "Starting LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh
;;
stop)
echo "Stopping LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/shutdown.sh
;;
logs)
echo "See the logs of the LifeRay Web Portal."
tail -f /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/catalina.out
;;
status)
# Check to see if the process is running
ps aux|grep -i liferay
;;
 
*)
echo “LifeRay Web Portal Service”
echo $”Usage: $0 {start|stop|status|logs}”
exit 1
esac
exit 0
For CentOS:

#!/bin/bash
# chkconfig: 2345 90 10
# description: Liferay Service
# LifeRay Startup Service script v1.0 by Faraz Haider 6 May 2012
# acts as startup service script for LifeRay Portal.
# USAGE: start|stop|status|logs
#
case "$1" in
start)
echo "Starting LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
#export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh
;;
stop)
echo "Stopping LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
#export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/shutdown.sh
;;
logs)
echo "See the logs of the LifeRay Web Portal."
tail -f /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/catalina.out
;;
status)
# Check to see if the process is running
ps aux|grep -i liferay
;;
 
*)
echo “LifeRay Web Portal Service”
echo $”Usage: $0 {start|stop|status|logs}”
exit 1
esac
exit 0
First two comments real important.
Make file executable:

chmod 755 /etc/init.d/liferay6
update-rc.d tomcat7 defaults
For CentOS:
chmod 755 /etc/init.d/liferay6
chkconfig liferay6 on

PS: only start,stop and status works
Reboot and be happy.

Change Tomcat port

Default port is 8080 but in not prety good becouse link www.example.com:8080 looks like a hell.
So go to home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/conf/server.xml. Find part:

 
And change port 8080 to what you want. I use 80 port for my site address www.example.com.

понедельник, 15 июля 2013 г.

Install php+FastCGI+nginx on Ubuntu.

Im continue create my super-amazing-web-GIS-application. I have a weak hardware so i have choice between 2 server side languages php and node.js. With php i can work now and there but for using node.js i have to read tons of books and miles of forums. So i have php i choose you!


1. Installing.

In previous part we already install nginx and fastCGI. So now we need only php. I will make php+fastCGI not php+php-rgm just becouse im already have fastcgi. If someone will write in comments why i have to use php-rgm i will glad.


Install php:


apt-get install php5 nginx php5-cgi

I was not install mySQL becouse i will use PostgreSQL+PostGIS for spatial data.


2. FastCGI configuration.

Create file /usr/bin/php-fastcgi and put into:


#! /bin/sh
PHP_FCGI_CHILDREN=3
PHP_FCGI_MAX_REQUESTS=1000
exec /usr/bin/php5-cgi

Create file /etc/init.d/init-fastcgi and put into:


#!/bin/bash
PHP_SCRIPT="/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-fastcgi"
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php5-cgi
RETVAL=$?
;;
restart)
killall -9 php5-cgi
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: sudo /etc/init.d/init-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

Make files executable:


chmod 755 /usr/bin/php-fastcgi
chmod 755 /etc/init.d/init-fastcgi 
3. nginx configuration.

You can create new file /etc/nginx/sites-enabled/your-file-name for server configuration:


server {
 listen 80;
 listen [::]:80 default_server ipv6only=on;

 root /srv/www/localhost/public_html;
 access_log /srv/www/localhost/logs/access.log;
 error_log /srv/www/localhost/logs/error.log;
 #index index.html index.htm;

 # Make site accessible from http://localhost/
 server_name localhost;

 location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  try_files $uri $uri/ /index.html;
  # Uncomment to enable naxsi on this location
  # include /etc/nginx/naxsi.rules
 }

 location /doc/ {
  alias /usr/share/doc/;
  autoindex on;
  allow 127.0.0.1;
  allow ::1;
  deny all;
 }
 location ~\.php$ {
  root /srv/www/localhost/public_html;
  include /etc/nginx/fastcgi_params;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param QUERY_STRING $query_string;
  fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
 }

}

But i use default file so i just add:


 location ~\.php$ {
  root /srv/www/localhost/public_html;
  include /etc/nginx/fastcgi_params;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param QUERY_STRING $query_string;
  fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
 }

into /etc/nginx/sites-enabled/default.


4. Site directory.

Its all with configurations. Now you can start FastCGI script:


Now we need to create directory for our site and log directory:


/srv/www/localhost/public_html
/srv/www/localhost/logs

In public_html keeped all site content.


5. Results.

Its all with configurations. Now you can start FastCGI script:


sudo /etc/init.d/init-fastcgi start

And start nginx:


/etc/init.d/nginx start

Create file test.php in our site directory with:



Go to the localhost/test.php and if you do all right you'll see standart phpinfo() output:


Its mean that php+nginx work fine.


In my case i get a 404 error becouse nginx tried to find test.php in standart nginx directory /var/www. Restart of nginx and fastcgi not help me, i was forced to reboot machine. But after all work fine.
Another problem was with permissions. So dont forget set to site directory:


 
sudo chmod -R 755 /srv/www/localhost/public_html
6. Enable PostgreSQL.

Its all nice but i will need PostgreSQL support in php. Now we need to install PostgreSQL module.


 
sudo apt-get install php5-pgsql

Restart fastCGI


 
sudo /etc/init.d/init-fastcgi restart

And go to localhost/test.php again to make sure that PostgreSQL enabled. You gonna see that part:


Its mean all works fine.