How can I display characters in a map by mapfile? - gis

I'm trying to show a map using postGIS+Mapserver. And I've displayed a PNG picture in my WEB.
However, I want to show some charactors in the map, just like this:
mapserv demo http://demo.mapserver.org/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-4.map&layer=states_poly&layer=states_line&mode=map
this is the example from Mapserver
Now I'm using database(postgreSQL), but not a shape file. How can I add the charactors then?
Here is a part of my mapfile:
LAYER
CONNECTIONTYPE postgis
NAME "state"
//Connect to a remote spatial database
CONNECTION "user=postgres dbname=*** host=*** password=***"
PROCESSING "CLOSE_CONNECTION=DEFER"
DATA "the_geom from province"
STATUS ON
TYPE POLYGON
CLASS
STYLE
COLOR 122 122 122
OUTLINECOLOR 0 0 0
END
LABEL
COLOR 132 31 31
SHADOWCOLOR 218 218 218
SHADOWSIZE 2 2
TYPE TURETYPE
FONT arial-bold
SIZE 12
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
END
END
END
Some said adding a "TEXT ([*])" in "LABEL", but I don't know howto?
Thanks for your help!

You should use the LABELITEM directive with the name of the table's field containing the text you want to render:
...
DATA "the_geom from province"
LABELITEM "<field_name>"
STATUS ON
...
Check the map file documentation for further details
http://mapserver.org/mapfile/layer.html

The amercader's answer above is quite correct. However, I solved it from amercader's help, but a bit differences, just using subquery.
Here is a sectional code:
LAYER
CONNECTIONTYPE postgis
NAME "state"
//# Connect to a remote spatial database
CONNECTION "user=postgres dbname=*** host=*** password=***"
PROCESSING "CLOSE_CONNECTION=DEFER"
DATA "the_geom from (select gid, the_geom, name from province) as subquery using unique gid using srid=4326"
STATUS ON
TYPE POLYGON
LABELITEM "name"
CLASS
STYLE
...
END
LABEL
...
END
END
END
The key point is "data" attribute, adding a subquery; as well as the "labelitem"'s parameter must be the same as selecting in subquery.
amercader told me that the subquery is unnecessary (see comments). It's cool!
I hope these words can give a helping hand to other programmers using the mapserver.
And thanks amercader.

Related

How to list all layers on Geopackage using pyqgis?

I am studying about pyqgis (using the pyqgis cookbook and started loading a vector layer.
So far I was able to open a layer that I already knew exist on a geopackge.
iface.addVectorLayer("./bcim_2016_21_11_2018.gpkg|layername=lim_unidade_federacao_a", "Nome Vetor", "ogr")
Now, I am wondering how could I list all layers hosted on a geopackage, so a can define which layer to load?
Thansk in advance
Felipe
I have just found this possibility on PyQGIS CookBook - cheatsheet, which answer my question.
from qgis.core import QgsVectorLayer, QgsProject
fileName = "/path/to/gpkg/file.gpkg"
layer = QgsVectorLayer(fileName,"test","ogr")
subLayers =layer.dataProvider().subLayers()
for subLayer in subLayers:
name = subLayer.split('!!::!!')[1]
uri = "%s|layername=%s" % (fileName, name,)
# Create layer
sub_vlayer = QgsVectorLayer(uri, name, 'ogr')
# Add layer to map
QgsProject.instance().addMapLayer(sub_vlayer)
Felipe, all layers are stored into gpkg_geometry_columns. So you should query this table using either QSqlDatabase from Qt or sqlite3.
To query the table name, column name and geometry type you can do the following:
select table_name, column_name, geometry_type_name from gpkg_geometry_columns
Hope I could help you!
Philipe

How to find a utf8 code from html document?

I'm currently scraping info from a website which uses icon fonts to identify information. When I find the element that contains the icon I get the "󲁋" character as expected. I want to identify the utf8 code of the character and as such be able to identify which symbol was used.
I'm looking to do something along these lines:
For Each HTMLElement in HTMLDocument.getElementsbyClassName("icon-class")
utf8code = HTMLElement.innerText
If utf8code = U+00AE Then
'do things
End If
Next
Ok, Whilst I wasn't able to fully achieve the goal of identifying the utf8 code of any character I did manage to find a way to identify the characters for my use case.
As it turned out, in my case there are around 30 characters and they appear more or less sequentially in the UTF8 codepage. Then the subject was to understand how the UTF8 code is formed, and user #RemyLebeau helped point me in the right direction. This video was very helpful for that: https://youtu.be/MijmeoH9LT4
My own summation is as follows:
1st byte: remove the first n+1 bits where n = the total number of bytes found
2nd - nth byte: remove the first two bits
the result should be combined starting from the rightmost bit and moving left, any spaces left to make a multiple of 8 should be filled with 0s.
so as in my example with 4 bytes:
243, 178, 129, 139
11110011, 10110010, 10000001, 10001011
11110-011, 10-110010, 10-000001, 10-001011
000(011)(11, 0010)(0000, 01)(001011)
00001111, 00100000, 01001011
F, 20, 4B
now the code I used to help identify which character I was finding:
Dim utf8Encoding As New System.Text.UTF8Encoding(True)
Dim encodedString() As Byte
encodedString = utf8Encoding.GetBytes(HTML_Element.innerText)
Select Case encodedstring(3)
Case 147
Case 155
End Select
In my particular case I was able to use a hashtable to relate the value of the 4th byte to a separate value that I needed.
Is this a good solution? no, it only works in specific cases and being able to simply obtain the UTF8 code would create a solution that is more effective and elegant for all use cases. But as this is a project for personal use only, and through a combination of lack of personal understanding and lack of people willing to help me understand, this solution works for me and so I figured I would include it in case anybody finds themselves in a similar situation where the above shortcut might help.

IDL compare 1000 tifs from Meteosat and create a new one

I need to compare the bands 2,3,6 and 9 of the Meteosat-8 all 15min. I already did the calculation for the brightness temperature and I managed to read all Tifs into IDL.
Now i did some Ratios. Like B6-B4, B9-3... Now I want to create a new Tif, where it writes (and later add up) a 1 or a 0 in it when some conditions are reached.
The result should be a Tif, where I have the amount of the "1" in every pixel.
I think I have to create a new array with the cols/rows and write after every "for loop" the 1 and 0 in it and add it up every time.
Thanks!
bumi
I managed it to read tiffs and compare them in a new tif.
I did a for loop to load all paths in.
The program works until there is a missing file (path doesn't exist). So I want to skip (continue) all the missing "paths".
I think, I can do it with file_info or file_test.
x=file_info(filepath(path), exists)
if x eq 0 then continue
exists: True(1) if the file exists. False (0) if it does not exists.
thanks

Cypher LOAD CSV - how to create a linked list of nodes ordered by a property?

Im new to Neo4j and looking for some guidance :-)
Basically I want to create the graph below from the csv below. The NEXT relationship is created between Points based on the order of their property sequence. I would like to be able to ignore if sequences are consecutive. Any ideas?
(s1:Shape)-[:POINTS]->(p1:Point)
(s1:Shape)-[:POINTS]->(p2:Point)
(s1:Shape)-[:POINTS]->(p3:Point)
(p1)-[:NEXT]->(p2)
(p2)[:NEXT]->(p3)
and so on
shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled
"1-700-y11-1.1.I","53.42646060879","-6.23930113514121","1","0"
"1-700-y11-1.1.I","53.4268571616632","-6.24059395687542","2","96.6074531286277"
"1-700-y11-1.1.I","53.4269700485041","-6.24093540883784","3","122.549696670773"
"1-700-y11-1.1.I","53.4270439028769","-6.24106779537932","4","134.591291249566"
"1-700-y11-1.1.I","53.4268623569266","-6.24155684094256","5","172.866609667575"
"1-700-y11-1.1.I","53.4268380666968","-6.2417384245122","6","185.235926544428"
"1-700-y11-1.1.I","53.4268874080753","-6.24203735638874","7","205.851454672516"
"1-700-y11-1.1.I","53.427394066848","-6.24287421729846","8","285.060040065768"
"1-700-y11-1.1.I","53.4275257974236","-6.24327509689195","9","315.473852717259"
"1-700-y11-1.2.O","53.277024711771","-6.20739084216546","1","0"
"1-700-y11-1.2.O","53.2777605784999","-6.20671521402849","2","93.4772699644143"
"1-700-y11-1.2.O","53.2780318605927","-6.2068238246152","3","124.525619356934"
"1-700-y11-1.2.O","53.2786209984572","-6.20894363498438","4","280.387737910482"
"1-700-y11-1.2.O","53.2791038678913","-6.21057305710353","5","401.635418300665"
"1-700-y11-1.2.O","53.2790975844245","-6.21075327761739","6","413.677012879457"
"1-700-y11-1.2.O","53.2792296384738","-6.21116766400758","7","444.981964564454"
"1-700-y11-1.2.O","53.2799500357098","-6.21065767664905","8","532.073870043666"
"1-700-y11-1.2.O","53.2800290799386","-6.2105343995296","9","544.115464622458"
"1-700-y11-1.2.O","53.2815594673093","-6.20949562301196","10","727.987702875002"
It is the 3rd part that I cant finish. Creating the NEXT relationship!
//1. Create Shape
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM
'file:///D:\\shapes.txt' AS csv
With distinct csv.shape_id as ids
Foreach (x in ids | merge (s:Shape {id: x} ));
//2. Create Point, and Shape to Point relationship
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM
'file:///D:\\shapes.txt' AS csv
MATCH (s:Shape {id: csv.shape_id})
with s, csv
MERGE (s)-[:POINTS]->(p:Point {id: csv.shape_id,
lat : csv.shape_pt_lat, lon : csv.shape_pt_lat,
sequence : toInt(csv.shape_pt_sequence), dist_travelled : csv.shape_dist_traveled});
//3.Create Point to Point relationship
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM
'file:///D:\\shapes.txt' AS csv
???
You'll want APOC Procedures installed for this one. It has both a means of batch processing, and a quick way to link all nodes in a collection together.
Since you already have all shapes the the points of the shape in the db, you don't need to do another load csv, just use the data you've got.
We'll use apoc.periodic.iterate() to batch process each shape, and apoc.nodes.link() to link all ordered points in the shape by relationships.
CALL apoc.periodic.iterate(
"MATCH (s:Shape) RETURN s",
"WITH {s} as shape
MATCH (shape)-[:POINTS]->(point:Point)
WITH shape, point
ORDER by point.sequence ASC
WITH shape, COLLECT(point) as points
CALL apoc.nodes.link(points,'NEXT')",
{batchSize:1000, parallel:true}) YIELD batches, total
RETURN batches, total
EDIT
Looks like there may be a bug when using procedure calls within the apoc.periodic.iterate() where no mutating operations occur (attempted this after including a SET operation in the second part of the query to set a property on some nodes, the property was not added).
Unsure if this is a general case of procedure calls being executed within procedure calls, or if this is specific to apoc.periodic.iterate(), or if this only occurs with both iterate() and link().
I'll file a bug if I can learn more about the cause. In the meantime, if you don't need batching, you can forgo apoc.periodic.iterate():
MATCH (shape:Shape)-[:POINTS]->(point:Point)
WITH shape, point
ORDER by point.sequence ASC
WITH shape, COLLECT(point) as points
CALL apoc.nodes.link(points,'NEXT')

Best way to index very long filepaths in mysql

Given the following filepaths, stored in a mysql database:
.//.git/refs/remotes/origin/HEAD
.//.git/refs/tags
.//__init__.py
.//__init__.pyc
.//forms.py
.//forms.pyc
.//models.py
.//models.pyc
.//settings.py
.//settings.pyc
.//static
.//static/css
.//static/css/all.css
.//static/images
.//static/images/bg.png
.//static/images/favicon.ico
.//static/images/pds-header-logo.png
.//static/images/pds-logo.png
.//static/images/revolver.png
.//static/js
.//static/js/all.js
.//templates
.//templates/base.html
.//templates/default.html
.//templates/overview.html
.//urls.py
.//urls.pyc
.//views.py
.//views.pyc
.//wsgi.py
.//wsgi.pyc
Someone needs to be able to search the path. For example if the user searched for "static", it would return the results with "static " in the path:
.//static
.//static/css
.//static/css/all.css
.//static/images
.//static/images/bg.png
.//static/images/favicon.ico
.//static/images/pds-header-logo.png
.//static/images/pds-logo.png
.//static/images/revolver.png
.//static/js
.//static/js/all.js
The search that I currently have is something like:
`SELECT path FROM files WHERE path LIKE '%search%';`
Is there a way to index this column / improve this search (remove the LIKE %%), as I probably have 1M+ filepaths on this system. Note that the filepath could be 200+ characters.
You can't. Wildcard search won't make use of index.
If you index the file path, you can only best support queries like
/static/images/%
Given your scenario, if you want to to allow wildcard search,
your best bet is to explode the directory to become multiple keywords:
static
images
revolver
.png
Then store each of the keyword into a keyword table,
and build the relationship.
When you perform the wildcard search is actually search the keyword table.
I guess you could actually have a "index of partial names". Something like this:
id ! name ! parent
---------------------
1 ! static ! 0 // at root.
2 ! css ! 1 // Parent is "static"
3 ! all.css ! 2 // parent is css
4 ! images ! 1 // parent is static
5 ! bg.png ! 4 // images.
It will need a bit of work to read out the original filename, unless you store that as well.