Monday, September 22, 2014

Realtime data exchange across enterprise using udp

Hello friends, its been long time since I wrote something on this blog site. For some time I off tracked myself from core GIS. Was busy in doing some real time messaging framework design. Did something cool on udp based reliable messaging and gis information exchange. The technology that I developed is all about sharing realtime data across enterprise through radio network. Later found somebody in the market doing similar thing. Have a look on Realtime Innovations. It does quite good stuff.

Mostly distributed caching/load balancing happens based on TCP at the lower level. But the same thing can be done using UDP. UDP by itself unreliable which means packet that is sent for delivery may or may not reach the destination. There may be chances of duplicate packets across nodes while on radio network. There may not be any packet sequencing while reaching the destination. All these are headache of using UDP. Still, people uses UDP for better bandwidth use and its multicast/broadcast facility.

I want to share some quick tips to other developers who are new to java socket programming to make their life easier while doing udp socket communication:
  1. DO usual socket creation steps like creating DatagramSocket/MulticastSocket based on your requirement
  2. Make sure you have set reusable address property on the socket object. It helps you you bind another socket on the same port
  3. Join a multicast group if you want to receive multicast packets
  4. MOST important set socket send/receive buffer size properly set. By default it is 8KB for a linux machine. Set some big value (i.e. 2MB) based on the traffic on the receiving port
  5. Prepare each packet below MTU level(i.e 1024 bytes). Generally network MTU(maximum transmission unit) is 1500 bytes. By making packet size below MTU, you overcome the risk of network packet fragmentation during transmission.
  6. Close your socket after job is done
  7. Leave multicast group
Feel free to contact me.



Wednesday, May 29, 2013

GDAL 1.9.2 OGR plugin driver for GeoMedia MDB

GDAL 1.9.2 latest stable release provide support for GeoMedia Acccess DB reading capability. GDAL uses jackcess jar in order to   read tables inside MDB store. However it does not properly read GeoMedia metadata and coordinate system information. Text , line geometry reading is not supported. GDAL mdb driver only supports Albers Conical projection as of now.

On linux, user can build the GDAL provided mdb driver by configuring --with-mdb flag associated with JVM lib settings. By this actually GDAL creates a dependency over jvm so/dll. 

For windows compilation you have to create a makefile.vc for mdb driver. Also you need to update nmake.opt to include jvm lib as dependent library. Update ogrsf_frmts makefile to include mdb obj files for ogr lib generation.

I did not want to make any modification over GDAL code which will actually put me in trouble while upgrading to new library. To make my modification detached from original GDAL code, I have created a new ogr driver for MDB. My new driver ,say roltamdb, which solves all metadata reading issues and supports variety of projections like PC, LCC, MER etc.. and it also supports TextPointGeometry and LineGeometry reading capability.

Over windows I'm able to create separate dll ogr_roltamdb.dll using gdal_i.lib and jvm.lib. I have set the OGR_DRIVER_PATH environment variable to locate my new dll. Now while I invoked "ogrinfo --formats" command, my driver is listed by ogr/gdal.

Initially I had lots of issue in building the new driver over linux 64bit machine, like LD_SHARED is not configured, not able to find main etc. While searching the web for resolution, noticed that lots of people having the same headache. I lost one day to figure out the problem. BTW I'm new to linux development. See the details below if anyone want to create your own OGR driver as a separate plugin.

For linux 64bit compile you need to configure GDAL first

# export CFLAGS="-fPIC -m64"
# export CXXFLAGS="-fPIC -m64"
# ./configure --with-java=/home/jdk1.6.0_43 --with-jvm-lib=/home/jdk1.6.0_43/jre/lib/amd64/server -enable-shared -with-pic --without-libtool
# make -j8
# make install

Create a new GNUmakefile for the new driver(roltamdb) as below -

--------------------------------------------------------------
include ../../../GDALmake.opt

OBJ     =       ogrroltamdbdatasource.o ogrroltamdblayer.o ogrroltamdbdriver.o \
                ogrroltamdbjackcess.o ogrroltageomediageometry.o

CPPFLAGS        :=      -I.. $(GDAL_INCLUDE) $(JAVA_INC) $(CPPFLAGS)

PLUGIN_SO =     ogr_roltamdb.so

JVM_LIB =        -L/home/jdk1.6.0_43/jre/lib/amd64/server -ljvm

default:        $(OBJ:.o=.$(OBJ_EXT)) plugin

clean:
        rm -f *.o $(O_OBJ) *.so *.lo

install-obj:    $(O_OBJ:.o=.$(OBJ_EXT))

$(OBJ) $(O_OBJ):        ogr_mdb.h

plugin: $(PLUGIN_SO)

$(PLUGIN_SO):   $(OBJ)
        $(LD_SHARED) $(OBJ) $(GDAL_SLIB_LINK) \
        $(JVM_LIB) -o $(PLUGIN_SO)

install: plugin
         $(INSTALL_LIB) $(PLUGIN_SO) $(DESTDIR)$(INST_LIB)

-------------------------------------------------------------

# make 
# make install

Your new driver should be up and running!! Enjoy..  

Wednesday, March 20, 2013

Add two big numbers


A simple program to add two big numbers -

#include <iostream>
#include <string>
using namespace std;

string add(string str1,string str2)
{
string sumstr;

string minstr,maxstr;
if(str1.length() !=str2.length())
{
maxstr = str1.length()>str2.length()?str1:str2;
minstr = str1.length()<str2.length()?str1:str2;
}
else
{
maxstr = str1;
minstr = str2;
}

sumstr = "0"+ maxstr;

string::reverse_iterator minrev = minstr.rbegin();
string::reverse_iterator maxrev = maxstr.rbegin();

string::reverse_iterator sumrev = sumstr.rbegin();
int carry = 0;
while(minrev != minstr.rend())
{
*sumrev += *minrev - '0' + carry;
if(*sumrev > '9')
{
*sumrev -= 10;
carry = 1;
}
else
{
carry = 0;
}
++sumrev;
++minrev;
}

while(sumrev != sumstr.rend() && carry ==1)
{
*sumrev += 1;
if(*sumrev > '9')
{
*sumrev -= 10;
*(sumrev+1) += 1;

if(*(sumrev+1) < '9')
carry = 0;
else
*(sumrev+1) -= 1;
}
else
carry = 0;

++sumrev;
}

if(sumstr.at(0) == '0')
sumstr.erase(0,1);

return sumstr;
}

int main(int argc, char* argv[])
{
while(1)
{
string str1,str2;
cout<<"Enter number1: ";
cin >> str1;
cout<<"Enter number2: ";
cin >> str2;

string result = add(str1,str2);

cout<<"Result: "<<result<<endl;
}
return 0;
}

Monday, June 11, 2012

Convert GeoMedia styles to geotools SLD format - Solution

If you have stored GeoMedia legend entry styles in an XML file in a specific format, you can directly convert them to SLD using XSLT.

I have written a .Net command for GeoMedia which iterates over all legend entries (thematic legends are not included) and stores all style properties in an XML file. Later using java, I have processed that xml based on connection and created separate sub-xml. Then applied the xslt over each subxml to generate the SLD file. Now I'm able to load the data file (MDB) along with style in uDig using the SLD.

Initially I was searching for such template over web to generate SLD from any known format but didn't find one. So I have written my own. You can find lots of sample to generate a subxml from an existing big xml file and how to use XSLT on-the-fly to get an output xml. See the XSLT below -

<?xml version="1.0" encoding="UTF-8"?>
<!--smaity - 12-June-2012
Style transformation template for GeoMedia style properties to OGC SLD format. Copyright All rights reserved. mrDOTsajalATgmailDOTcom-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn xsl">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
  <xsl:for-each select="Connection">
   <xsl:if test="@type = 'Vector'">
    <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
     <sld:Name>
      <xsl:value-of select="name"/>
     </sld:Name>
     <xsl:for-each select="Layers">
      <xsl:for-each select="Layer">
       <sld:UserLayer>
        <sld:Name>
         <xsl:value-of select="@name"/>
        </sld:Name>
        <sld:LayerFeatureConstraints>
         <sld:FeatureTypeConstraint/>
        </sld:LayerFeatureConstraints>
        <sld:UserStyle>
         <sld:Name>Default Styler</sld:Name>
         <sld:Title/>
         <sld:FeatureTypeStyle>
          <sld:Name>
           <xsl:value-of select="@name"/>
          </sld:Name>
          <sld:FeatureTypeName>Feature</sld:FeatureTypeName>
          <sld:SemanticTypeIdentifier>generic:geometry</sld:SemanticTypeIdentifier>
          <xsl:for-each select="Style">
           <xsl:if test="Displayable='True'">
            <sld:Rule>
             <sld:MaxScaleDenominator>1.7976931348623157E308</sld:MaxScaleDenominator>
             <sld:Name>Default</sld:Name>
             <xsl:choose>
              <xsl:when test="StyleType='Symbol Style'">
               <xsl:if test="SymbolRendererName=''">
                <sld:PointSymbolizer>
                 <sld:Graphic>
                  <sld:Mark>
                   <sld:WellKnownName>circle</sld:WellKnownName>
                   <xsl:if test="Displayable='True'">
                    <sld:Fill>
                     <sld:CssParameter name="fill">
                      <xsl:variable name="color">
                       <xsl:value-of select="empty"/>
                       <xsl:call-template name="ConvertDecToHex">
                        <xsl:with-param name="index">
                         <xsl:value-of select="OverrideColor"/>
                        </xsl:with-param>
                       </xsl:call-template>
                      </xsl:variable>
                      <xsl:variable name="finalcolor">
                       <xsl:choose>
                        <xsl:when test="string-length(string($color)) = 6">
                         <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 4">
                         <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 2">
                         <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                        </xsl:when>
                        <xsl:otherwise>
                         <xsl:value-of select="concat('00','00','00')"/>
                        </xsl:otherwise>
                       </xsl:choose>
                      </xsl:variable>
                      <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="fill-opacity">
                      <ogc:Literal>
                       <xsl:value-of select="1 - Translucency div 100"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                    </sld:Fill>
                    <sld:Stroke>
                     <sld:CssParameter name="stroke">
                      <xsl:variable name="color">
                       <xsl:call-template name="ConvertDecToHex">
                        <xsl:with-param name="index">
                         <xsl:value-of select="OverrideColor"/>
                        </xsl:with-param>
                       </xsl:call-template>
                      </xsl:variable>
                      <xsl:variable name="finalcolor">
                       <xsl:choose>
                        <xsl:when test="string-length(string($color)) = 6">
                         <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 4">
                         <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 2">
                         <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                        </xsl:when>
                        <xsl:otherwise>
                         <xsl:value-of select="concat('00','00','00')"/>
                        </xsl:otherwise>
                       </xsl:choose>
                      </xsl:variable>
                      <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-linecap">
                      <ogc:Literal>butt</ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-linejoin">
                      <ogc:Literal>miter</ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-opacity">
                      <ogc:Literal>1.0</ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-width">
                      <ogc:Literal>
                       <xsl:value-of select="Width div 100 div 0.2645"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-dashoffset">
                      <ogc:Literal>0.0</ogc:Literal>
                     </sld:CssParameter>
                    </sld:Stroke>
                   </xsl:if>
                  </sld:Mark>
                  <sld:Opacity>
                   <ogc:Literal>
                    <xsl:value-of select="1-Translucency div 100"/>
                   </ogc:Literal>
                  </sld:Opacity>
                  <sld:Size>
                   <ogc:Literal>
                    <xsl:value-of select="Size div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:Size>
                  <sld:Rotation>
                   <ogc:Literal>
                    <xsl:value-of select="Rotation"/>
                   </ogc:Literal>
                  </sld:Rotation>
                 </sld:Graphic>
                </sld:PointSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Text Style'">
               <xsl:if test="Displayable='True'">
                <sld:PointSymbolizer>
                 <sld:Graphic>
                  <sld:Mark>
                   <sld:WellKnownName>square</sld:WellKnownName>
                  </sld:Mark>
                  <sld:Opacity>
                   <ogc:Literal>1.0</ogc:Literal>
                  </sld:Opacity>
                  <sld:Size>
                   <ogc:Literal>-1.0</ogc:Literal>
                  </sld:Size>
                  <sld:Rotation>
                   <ogc:Literal>0.0</ogc:Literal>
                  </sld:Rotation>
                 </sld:Graphic>
                </sld:PointSymbolizer>
                <sld:TextSymbolizer>
                 <sld:Label>
                  <ogc:PropertyName>Text</ogc:PropertyName>
                 </sld:Label>
                 <sld:Font>
                  <sld:CssParameter name="font-family">
                   <ogc:Literal>
                    <xsl:value-of select="FontName"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-size">
                   <ogc:Literal>
                    <xsl:value-of select="FontSize div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-style">
                   <xsl:choose>
                    <xsl:when test="FontItalic='True'">
                     <ogc:Literal>italic</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-weight">
                   <xsl:choose>
                    <xsl:when test="FontBold='True'">
                     <ogc:Literal>Bold</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                 </sld:Font>
                 <sld:LabelPlacement>
                  <sld:PointPlacement>
                   <sld:AnchorPoint>
                    <sld:AnchorPointX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:AnchorPointX>
                    <sld:AnchorPointY>
                     <ogc:Literal>0.5</ogc:Literal>
                    </sld:AnchorPointY>
                   </sld:AnchorPoint>
                   <sld:Displacement>
                    <sld:DisplacementX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementX>
                    <sld:DisplacementY>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementY>
                   </sld:Displacement>
                   <sld:Rotation>
                    <ogc:Sub>
                     <ogc:Literal>360.0</ogc:Literal>
                     <ogc:PropertyName>Angle</ogc:PropertyName>
                    </ogc:Sub>
                   </sld:Rotation>
                  </sld:PointPlacement>
                 </sld:LabelPlacement>
                 <sld:Fill>
                  <sld:CssParameter name="fill">
                   <xsl:variable name="color">
                    <xsl:call-template name="ConvertDecToHex">
                     <xsl:with-param name="index">
                      <xsl:value-of select="Color"/>
                     </xsl:with-param>
                    </xsl:call-template>
                   </xsl:variable>
                   <xsl:variable name="finalcolor">
                    <xsl:choose>
                     <xsl:when test="string-length(string($color)) = 6">
                      <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 4">
                      <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 2">
                      <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                     </xsl:when>
                     <xsl:otherwise>
                      <xsl:value-of select="concat('00','00','00')"/>
                     </xsl:otherwise>
                    </xsl:choose>
                   </xsl:variable>
                   <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="fill-opacity">
                   <ogc:Literal>
                    <xsl:value-of select="1 - Translucency div 100"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                 </sld:Fill>
                 <VendorOption name="spaceAround">-1</VendorOption>
                 <VendorOption name="conflictResolution">false</VendorOption>
                </sld:TextSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Simple Line Style'">
               <xsl:if test="Displayable='True'">
                <sld:LineSymbolizer>
                 <sld:Stroke>
                  <sld:CssParameter name="stroke">
                   <xsl:variable name="color">
                    <xsl:call-template name="ConvertDecToHex">
                     <xsl:with-param name="index">
                      <xsl:value-of select="Color"/>
                     </xsl:with-param>
                    </xsl:call-template>
                   </xsl:variable>
                   <xsl:variable name="finalcolor">
                    <xsl:choose>
                     <xsl:when test="string-length(string($color)) = 6">
                      <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 4">
                      <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 2">
                      <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                     </xsl:when>
                     <xsl:otherwise>
                      <xsl:value-of select="concat('00','00','00')"/>
                     </xsl:otherwise>
                    </xsl:choose>
                   </xsl:variable>
                   <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-linecap">
                   <ogc:Literal>butt</ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-linejoin">
                   <ogc:Literal>miter</ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-opacity">
                   <ogc:Literal>
                    <xsl:value-of select="1 - Translucency div 100"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-width">
                   <ogc:Literal>
                    <xsl:value-of select="Width div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-dashoffset">
                   <ogc:Literal>0</ogc:Literal>
                  </sld:CssParameter>
                 </sld:Stroke>
                </sld:LineSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Font Style'">
               <xsl:if test="Displayable='True'">
                <sld:TextSymbolizer>
                 <sld:Label>
                  <ogc:PropertyName>Text</ogc:PropertyName>
                 </sld:Label>
                 <sld:Font>
                  <sld:CssParameter name="font-family">
                   <ogc:Literal>
                    <xsl:value-of select="FontName"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-size">
                   <ogc:Literal>
                    <xsl:value-of select="FontSize div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-style">
                   <xsl:choose>
                    <xsl:when test="FontItalic='True'">
                     <ogc:Literal>italic</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-weight">
                   <xsl:choose>
                    <xsl:when test="FontBold='True'">
                     <ogc:Literal>Bold</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                 </sld:Font>
                 <sld:LabelPlacement>
                  <sld:PointPlacement>
                   <sld:AnchorPoint>
                    <sld:AnchorPointX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:AnchorPointX>
                    <sld:AnchorPointY>
                     <ogc:Literal>0.5</ogc:Literal>
                    </sld:AnchorPointY>
                   </sld:AnchorPoint>
                   <sld:Displacement>
                    <sld:DisplacementX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementX>
                    <sld:DisplacementY>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementY>
                   </sld:Displacement>
                   <sld:Rotation>
                    <ogc:Sub>
                     <ogc:Literal>360.0</ogc:Literal>
                     <ogc:PropertyName>Angle</ogc:PropertyName>
                    </ogc:Sub>
                   </sld:Rotation>
                  </sld:PointPlacement>
                 </sld:LabelPlacement>
                 <sld:Fill>
                  <sld:CssParameter name="fill">
                   <xsl:variable name="color">
                    <xsl:call-template name="ConvertDecToHex">
                     <xsl:with-param name="index">
                      <xsl:value-of select="Color"/>
                     </xsl:with-param>
                    </xsl:call-template>
                   </xsl:variable>
                   <xsl:variable name="finalcolor">
                    <xsl:choose>
                     <xsl:when test="string-length(string($color)) = 6">
                      <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 4">
                      <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 2">
                      <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                     </xsl:when>
                     <xsl:otherwise>
                      <xsl:value-of select="concat('00','00','00')"/>
                     </xsl:otherwise>
                    </xsl:choose>
                   </xsl:variable>
                   <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="fill-opacity">
                   <ogc:Literal>
                    <xsl:value-of select="1 - Translucency div 100"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                 </sld:Fill>
                 <VendorOption name="spaceAround">-1</VendorOption>
                 <VendorOption name="conflictResolution">false</VendorOption>
                </sld:TextSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Area Style'">
               <xsl:if test="Displayable='True'">
                <sld:PolygonSymbolizer>
                 <xsl:for-each select="Styles">
                  <xsl:choose>
                   <xsl:when test="StyleType='Boundary Styles'">
                    <xsl:if test="Displayable='True'">
                     <xsl:for-each select="Style">
                      <xsl:choose>
                       <xsl:when test="StyleType='Simple Line Style'">
                        <xsl:if test="Displayable='True'">
                         <sld:Stroke>
                          <sld:CssParameter name="stroke">
                           <xsl:variable name="color">
                            <xsl:call-template name="ConvertDecToHex">
                             <xsl:with-param name="index">
                              <xsl:value-of select="Color"/>
                             </xsl:with-param>
                            </xsl:call-template>
                           </xsl:variable>
                           <xsl:variable name="finalcolor">
                            <xsl:choose>
                             <xsl:when test="string-length(string($color)) = 6">
                              <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 4">
                              <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 2">
                              <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                             </xsl:when>
                             <xsl:otherwise>
                              <xsl:value-of select="concat('00','00','00')"/>
                             </xsl:otherwise>
                            </xsl:choose>
                           </xsl:variable>
                           <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-linecap">
                           <ogc:Literal>butt</ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-linejoin">
                           <ogc:Literal>miter</ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-opacity">
                           <ogc:Literal>1</ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-width">
                           <ogc:Literal>
                            <xsl:value-of select="Width div 100 div 0.2645"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-dashoffset">
                           <ogc:Literal>0</ogc:Literal>
                          </sld:CssParameter>
                         </sld:Stroke>
                        </xsl:if>
                       </xsl:when>
                       <xsl:otherwise>
                        <sld:Stroke>
                         <sld:CssParameter name="stroke">
                          <xsl:variable name="color">
                           <xsl:call-template name="ConvertDecToHex">
                            <xsl:with-param name="index">
                             <xsl:value-of select="Color"/>
                            </xsl:with-param>
                           </xsl:call-template>
                          </xsl:variable>
                          <xsl:variable name="finalcolor">
                           <xsl:choose>
                            <xsl:when test="string-length(string($color)) = 6">
                             <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                            </xsl:when>
                            <xsl:when test="string-length(string($color)) = 4">
                             <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                            </xsl:when>
                            <xsl:when test="string-length(string($color)) = 2">
                             <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                            </xsl:when>
                            <xsl:otherwise>
                             <xsl:value-of select="concat('00','00','00')"/>
                            </xsl:otherwise>
                           </xsl:choose>
                          </xsl:variable>
                          <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                          </ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-linecap">
                          <ogc:Literal>butt</ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-linejoin">
                          <ogc:Literal>miter</ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-opacity">
                          <ogc:Literal>1</ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-width">
                          <ogc:Literal>
                           <xsl:value-of select="Width div 100 div 0.2645"/>
                          </ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-dashoffset">
                          <ogc:Literal>0</ogc:Literal>
                         </sld:CssParameter>
                        </sld:Stroke>
                       </xsl:otherwise>
                      </xsl:choose>
                     </xsl:for-each>
                    </xsl:if>
                   </xsl:when>
                   <xsl:when test="StyleType='Fill Styles'">
                    <xsl:if test="Displayable='True'">
                     <xsl:for-each select="Style">
                      <xsl:choose>
                       <xsl:when test="StyleType='Simple Fill Style'">
                        <xsl:if test="Displayable='True'">
                         <sld:Fill>
                          <sld:CssParameter name="fill">
                           <xsl:variable name="color">
                            <xsl:call-template name="ConvertDecToHex">
                             <xsl:with-param name="index">
                              <xsl:value-of select="Color"/>
                             </xsl:with-param>
                            </xsl:call-template>
                           </xsl:variable>
                           <xsl:variable name="finalcolor">
                            <xsl:choose>
                             <xsl:when test="string-length(string($color)) = 6">
                              <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 4">
                              <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 2">
                              <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                             </xsl:when>
                             <xsl:otherwise>
                              <xsl:value-of select="concat('00','00','00')"/>
                             </xsl:otherwise>
                            </xsl:choose>
                           </xsl:variable>
                           <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="fill-opacity">
                           <ogc:Literal>
                            <xsl:value-of select="1-Translucency div 100"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                         </sld:Fill>
                        </xsl:if>
                       </xsl:when>
                      </xsl:choose>
                     </xsl:for-each>
                    </xsl:if>
                   </xsl:when>
                  </xsl:choose>
                 </xsl:for-each>
                </sld:PolygonSymbolizer>
               </xsl:if>
              </xsl:when>
             </xsl:choose>
            </sld:Rule>
           </xsl:if>
          </xsl:for-each>
         </sld:FeatureTypeStyle>
        </sld:UserStyle>
       </sld:UserLayer>
      </xsl:for-each>
     </xsl:for-each>
    </sld:StyledLayerDescriptor>
   </xsl:if>
  </xsl:for-each>
 </xsl:template>
 <xsl:template name="ConvertDecToHex">
  <xsl:param name="index"/>
  <xsl:if test="$index > 0">
   <xsl:call-template name="ConvertDecToHex">
    <xsl:with-param name="index" select="floor($index div 16)"/>
   </xsl:call-template>
   <xsl:choose>
    <xsl:when test="$index mod 16 &lt; 10">
     <xsl:value-of select="$index mod 16"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:choose>
      <xsl:when test="$index mod 16 = 10">A</xsl:when>
      <xsl:when test="$index mod 16 = 11">B</xsl:when>
      <xsl:when test="$index mod 16 = 12">C</xsl:when>
      <xsl:when test="$index mod 16 = 13">D</xsl:when>
      <xsl:when test="$index mod 16 = 14">E</xsl:when>
      <xsl:when test="$index mod 16 = 15">F</xsl:when>
      <xsl:otherwise>A</xsl:otherwise>
     </xsl:choose>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>