วันศุกร์ที่ 15 ธันวาคม พ.ศ. 2560

Postgres command

//Postgres 9.6 
http://www.postgresqltutorial.com/postgresql-string-functions/

// SELECT
select p_id,p_name from p_tb;

select p_id,p_name from p_tb;
where p_name like '%foo%';

// ADD column
alter table p_tb
add column p_id integer,
add column p_name character varying(250),
add column p_pk serial primary key;

// DELTE column
alter table p_tb
drop column p_name;

// RENAME column
alter table p_tb
rename column p_name to p_name_t;

// UPDATE column
update p_tb
set name_ul = name;

update p_tb
set name_ul = initcap(name) where language = 'vietnam';


:: String Functions ::

ASCII(‘A’) >>> 65
CHR(65)
CONCAT(‘A’,’B’,’C’)
CONCAT_WS  CONCAT(‘,’,’A’,’B’,’C’)
FORMAT(‘Hello %s’,’PostgreSQL’)

INITCAP(‘hI tHERE’)   >>>   Hi There

LEFT(‘ABC’,1)
LENGTH(‘ABC’)
LOWER(‘hI tHERE’)
LPAD(‘123′, 5, ’00’)
LTRIM(‘00123’)
MD5(‘ABC’)
POSTION(‘B’ in ‘A B C’)
REGEXP_MATCHES SELECT REGEXP_MATCHES(‘ABC’, ‘^(A)(..)$’, ‘g’);
REGEXP_REPLACE(‘John Doe’,'(.*) (.*)’,’\2, \1′);
REPEAT(‘*’, 5)

REPLACE(‘ABC’,’B’,’A’)   >>>   ‘AAC’

REVERSE(‘ABC’)
RIGHT(‘ABC’, 2)
RPAD(‘ABC’, 6, ‘xo’)
RTRIM(‘abcxxzx’, ‘xyz’)
SPLIT_PART(‘2017-12-31′,’-‘,2)
SUBSTRING(‘ABC’,1,1)
TRIM
UPPER(‘hI tHERE’)

วันพุธที่ 6 ธันวาคม พ.ศ. 2560

convert geographic coordinate system

การแปลงค่าพิกัดจากองศา ลิปดา ฟิลิปดา เป็น แบบองศาทศนิยม



การแปลงค่าพิกัดจาก
องศา ลิปดา ฟิลิปดา (hddd?ddd’ddd.ddd’’) และ องศา ลิปดา ฟิลิปดา (hddd?ddd.ddd’
เป็น แบบองศาทศนิยม (hddd.ddd?)
ตัวอย่างที่ องศา ลิปดา ฟิลิปดา (hddd?ddd’ddd.ddd’’)
Lat  13 ํ 45 53.7’’ N
Long  100 ํ 32' 17.9’’ E
ขั้นตอนที่ 1 หาค่าลิปดา นำค่าลิปดาหารด้วย 60 จะได้
Lat  13 ํ 45 53.7’’ N
ลิปดา = 45/60
ลิปดา = 0.75
Long  100 ํ 32' 17.9’’ E
ลิปดา = 32/60
ลิปดา = 0.533
ขั้นตอนที่ 2  หาค่าฟิลิปดา นำค่าฟิลิปดาหารด้วย 3600 จะได้
Lat  13 ํ 45 53.7’’ N
          ฟิลิปดา = 53.7/3600
          ฟิลิปดา = 0.014916
Long  100 ํ 32' 17.9’’ E
ฟิลิปดา = 17.9/3600
          ฟิลิปดา = 0.004972
ขั้นตอนที่ 3 นำค่าลิปดาจากขั้นตอนที่ 1 +  ค่าฟิลิปดาจากขั้นตอนที่ 2
Lat  13 ํ 45 53.7’’ N
ลิปดา = 45/60
ลิปดา = 0.75
Lat  13 ํ 45 53.7’’ N
          ฟิลิปดา = 53.7/3600
          ฟิลิปดา = 0.014916
Lat 13 ํ 45 53.7’’ N 
                     = 13 ํ + (0.75+0.014916)
                     = 13 ํ + 0.764916
ดังนั้น       Lat  = 13.764916N
Long  100 ํ 32' 17.9’’ E
ลิปดา = 32/60
ลิปดา = 0.533
Long  100 ํ 32' 17.9’’ E
ฟิลิปดา = 17.9/3600
          ฟิลิปดา = 0.004972
Long  100 ํ 32' 17.9’’ E 
                     = 100 ํ + (0.533+0.004972)
                     = 100 ํ + 0.537972
ดังนั้น       Long  = 100.537972E
สรุป
Lat  13 45 53.7’’ N                        Lat  13.764916N
Long  100 32' 17.9’’ E                    Long  100.537972E

วันศุกร์ที่ 6 ตุลาคม พ.ศ. 2560

ทำไมบาง tag ก็มี prefix บาง tag ก็ไม่มี ?

ใน SLD document จะมีบาง tag ที่มี prefix เช่น ogc: ที่เป็นเช่นนี้เพราะมีการกำหนดใน XML namespaces ไว้ที่ StyledLayerDescriptor Tag ที่อยู่บนสุด (บรรทัด 2-7) โดยระบุไว้ 2 XML namespaces , อันนึงเรียก xmlns และอีกอันเรียก xmlns:ogc

namespace แรก เป็น default ของ document  ดังนั้น tag ในส่วนของ namespace นี้ จึงไม่ต้องมี prefix  ส่วน namespace ถัดมา xmlns:ogc  tag ที่อยู่ในส่วนของ namespace นี้ ต้องมี prefix ogc:  แต่อันที่จริง namespace แรก ก็สามารถเรียกแบบ xmlns:sld ได้ แต่ถ้าเขียนแบบนี้แล้ว ก็ต้องเขียนทั้่งหมด

สรุปก็คือ  tags ควรจะมี prefix ของแต่ละ namespace

วันอังคารที่ 15 สิงหาคม พ.ศ. 2560

SLD Structure

การเขียน SLD ในแต่ละไฟล์จะต้องเริ่มต้นและปิดท้ายด้วยโครงสร้าง tag เปิดปิดเช่นนี้เสมอ
หมายเหตุ : ส่วนที่มีโครงสร้างเป็นสองแบบ   คลิก

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <NamedLayer>
        <Name>Rotated square</Name>
        <UserStyle>
            <Title>GeoServer SLD Cook Book: Rotated square</Title>
            <FeatureTypeStyle>
                <Rule>
                    <PointSymbolizer>
                        <Graphic>
                            <Mark>
                                <WellKnownName>square</WellKnownName>
                                <Fill>
                                    <CssParameter name="fill">#009900</CssParameter>
                                </Fill>
                            </Mark>
                            <Size>12</Size>
                            <Rotation>45</Rotation>
                        </Graphic>
                    </PointSymbolizer>
                </Rule>
            </FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>


<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">
    <NamedLayer>
        <Name>Rotated square</Name>
        <UserStyle>
            <Title>GeoServer SLD Cook Book: Rotated square</Title>
            <FeatureTypeStyle>
                <Rule>
                    <PointSymbolizer>
                        <Graphic>
                            <Mark>
                                <WellKnownName>square</WellKnownName>
                                <Fill>
                                    <CssParameter name="fill">#009900</CssParameter>
                                </Fill>
                            </Mark>
                            <Size>12</Size>
                            <Rotation>45</Rotation>
                        </Graphic>
                    </PointSymbolizer>
                </Rule>
            </FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>