Revision 47583

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Within.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_Within extends Functions.AbstractFunction {
36

  
37
    public ST_Within(SQLiteConnection conn) {
38
        super("ST_Within", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes1 = value_blob(0);
45
            if (bytes1 == null) {
46
                this.result();
47
                return;
48
            }
49
            byte[] bytes2 = value_blob(1);
50
            if (bytes2 == null) {
51
                this.result();
52
                return;
53
            }
54
            SQLiteConnection conn = this.getConnection();
55
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
56
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
57
            if (geom1 == null) {
58
                this.result();
59
                return;
60
            }
61
            Geometry geom2 = parser.parseToGeometry(conn, bytes2);
62
            if (geom2 == null) {
63
                this.result();
64
                return;
65
            }
66
            
67
            this.result(geom1.within(geom2) ? 1 : 0);
68
        } catch (Throwable ex) {
69
            throw new SQLException("Can't evaluate if the first geometry is within the second", ex);
70
        }
71
    }
72

  
73
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Area.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_Area extends Functions.AbstractFunction {
36

  
37
    public ST_Area(SQLiteConnection conn) {
38
        super("ST_Area", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes1 = value_blob(0);
45
            if (bytes1 == null) {
46
                this.result();
47
                return;
48
            }
49
            SQLiteConnection conn = this.getConnection();
50
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
51
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
52
            if (geom1 == null) {
53
                this.result();
54
                return;
55
            }
56
            this.result(geom1.area());
57
        } catch (Throwable ex) {
58
            throw new SQLException("Can't get geometry's area", ex);
59
        }
60
    }
61

  
62
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_AsText.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_AsText extends Functions.AbstractFunction {
36

  
37
    public ST_AsText(SQLiteConnection conn) {
38
        super("ST_AsText", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes1 = value_blob(0);
45
            if (bytes1 == null) {
46
                this.result();
47
                return;
48
            }
49
            SQLiteConnection conn = this.getConnection();
50
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
51
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
52
            if (geom1 == null) {
53
                this.result();
54
                return;
55
            }
56
            this.result(geom1.convertToWKTQuietly());
57
        } catch (Throwable ex) {
58
            throw new SQLException("Can't get geometry's WKT", ex);
59
        }
60
    }
61

  
62
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Y.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.primitive.Point;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Y extends Functions.AbstractFunction {
37

  
38
    public ST_Y(SQLiteConnection conn) {
39
        super("ST_Y", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes1 = value_blob(0);
46
            if (bytes1 == null) {
47
                this.result();
48
                return;
49
            }
50
            SQLiteConnection conn = this.getConnection();
51
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
52
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
53
            if (geom1 == null) {
54
                this.result();
55
                return;
56
            }
57
            this.result(((Point)geom1).getY());
58
        } catch (Throwable ex) {
59
            throw new SQLException("Can't get the coordinate Y of the geometry", ex);
60
        }
61
    }
62

  
63
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_GeometryN.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.primitive.Primitive;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
29
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
30
import org.sqlite.SQLiteConnection;
31

  
32
/**
33
 *
34
 * @author gvSIG Team
35
 */
36
@SuppressWarnings("UseSpecificCatch")
37
public class ST_GeometryN extends Functions.AbstractFunction {
38

  
39
    public ST_GeometryN(SQLiteConnection conn) {
40
        super("ST_GeometryN", conn);
41
    }
42

  
43
    @Override
44
    protected void xFunc() throws SQLException {
45
        try {
46
            byte[] bytes1 = value_blob(0);
47
            if (bytes1 == null) {
48
                this.result();
49
                return;
50
            }
51
            int n = value_int(1);
52
            SQLiteConnection conn = this.getConnection();
53
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
54
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
55
            if (geom1 == null) {
56
                this.result();
57
                return;
58
            }
59
            
60
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
61
            if( geom1 instanceof org.gvsig.fmap.geom.aggregate.Aggregate ) {
62
                Primitive p = ((org.gvsig.fmap.geom.aggregate.Aggregate) geom1).getPrimitiveAt(n);
63
                builder.setGeometry(conn, p);
64
            }
65
            byte[] bytes = builder.build();
66
            if (bytes == null) {
67
                this.result();
68
            } else {
69
                this.result(bytes);
70
            }
71
        } catch (Throwable ex) {
72
            throw new SQLException("Can't get the N component from the geometry", ex);
73
        }
74
    }
75

  
76
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Transform.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.cresques.cts.ICoordTrans;
26
import org.cresques.cts.IProjection;
27
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
28
import org.gvsig.fmap.crs.CRSFactory;
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
31
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
32
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
33
import org.sqlite.SQLiteConnection;
34

  
35
/**
36
 *
37
 * @author gvSIG Team
38
 */
39
@SuppressWarnings("UseSpecificCatch")
40
public class ST_Transform extends Functions.AbstractFunction {
41

  
42
    public ST_Transform(SQLiteConnection conn) {
43
        super("ST_Transform", conn);
44
    }
45

  
46
    @Override
47
    protected void xFunc() throws SQLException {
48
        try {
49
            byte[] bytes1 = value_blob(0);
50
            if (bytes1 == null) {
51
                this.result();
52
                return;
53
            }
54
            SQLiteConnection conn = this.getConnection();
55
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
56
            Geometry geom = parser.parseToGeometry(conn,bytes1);
57
            if (geom == null) {
58
                this.result();
59
                return;
60
            }
61
            
62
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
63
            
64
            IProjection  to_proj = null;
65
            IProjection from_proj = null;
66
            Integer to_srid = null;
67
            Integer from_srid = null;
68

  
69
            switch (args()) {
70
                case 2:
71
                    to_srid = value_int(1);
72
//                    to_srid = (Integer) DataTypeUtils.coerce(DataTypes.INT, getObject(args, 1), null);
73
//                    if (to_srid == null) {
74
//                        to_proj = CRSFactory.getCRS(value_text(1));
75
//                    } else {
76
//                        to_proj = CRSFactory.getCRS("EPSG:" + to_srid);
77
//                    }
78
                    to_proj = CRSFactory.getCRS("EPSG:" + to_srid);
79
                    from_proj = geom.getProjection();
80
                    break;
81

  
82
                case 3:
83
                    to_srid = value_int(2);
84
                    from_srid = value_int(1);
85
//                    to_srid = (Integer) DataTypeUtils.coerce(DataTypes.INT, getObject(args, 2), null);
86
//                    if (to_srid == null) {
87
//                        to_proj = CRSFactory.getCRS(getStr(args, 2));
88
//                    } else {
89
//                        to_proj = CRSFactory.getCRS("EPSG:" + to_srid);
90
//                    }
91
////                    from_proj = CRSFactory.getCRS(getStr(args, 1));
92
                    to_proj = CRSFactory.getCRS("EPSG:" + to_srid);
93
                    from_proj = CRSFactory.getCRS("EPSG:" + from_srid);
94
                    break;
95

  
96
                default:
97
                    throw new ExpressionRuntimeException("Incorrect number of arguments.");
98
            }
99
            ICoordTrans ct = from_proj.getCT(to_proj);
100
            Geometry reprojectedGeom = geom.cloneGeometry();
101
            reprojectedGeom.reProject(ct);
102
            builder.setGeometry(conn, reprojectedGeom);
103
            byte[] bytes = builder.build();
104
            if (bytes == null) {
105
                this.result();
106
            } else {
107
                this.result(bytes);
108
            }
109
        } catch (Throwable ex) {
110
            throw new SQLException("Can't transform the geometry", ex);
111
        }
112
    }
113

  
114
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Envelope.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Envelope extends Functions.AbstractFunction {
37

  
38
    public ST_Envelope(SQLiteConnection conn) {
39
        super("ST_Envelope", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes = value_blob(0);
46
            if (bytes == null) {
47
                this.result();
48
                return;
49
            }
50
            SQLiteConnection conn = this.getConnection();
51
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
52
            Geometry geom = parser.parseToGeometry(conn,bytes);
53
            if (geom == null) {
54
                this.result();
55
                return;
56
            }
57
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
58
            builder.setGeometry(conn, geom.getEnvelope().getGeometry());
59
            bytes = builder.build();
60
            if (bytes == null) {
61
                this.result();
62
            } else {
63
                this.result(bytes);
64
            }
65

  
66
        } catch (Throwable ex) {
67
            throw new SQLException("Can't get geometry's envelope", ex);
68
        }
69
    }
70

  
71
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_SetSRID.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.cresques.cts.IProjection;
26
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
27
import org.gvsig.fmap.crs.CRSFactory;
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.fmap.geom.primitive.Primitive;
30
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
31
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
32
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
33
import org.sqlite.SQLiteConnection;
34

  
35
/**
36
 *
37
 * @author gvSIG Team
38
 */
39
@SuppressWarnings("UseSpecificCatch")
40
public class ST_SetSRID extends Functions.AbstractFunction {
41

  
42
    public ST_SetSRID(SQLiteConnection conn) {
43
        super("ST_SetSRID", conn);
44
    }
45

  
46
    @Override
47
    protected void xFunc() throws SQLException {
48
        try {
49
            byte[] bytes1 = value_blob(0);
50
            if (bytes1 == null) {
51
                this.result();
52
                return;
53
            }
54
            String srid = value_text(1);
55
            SQLiteConnection conn = this.getConnection();
56
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
57
            Geometry geom = parser.parseToGeometry(conn,bytes1);
58
            if (geom == null) {
59
                this.result();
60
                return;
61
            }
62
            
63
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
64
            IProjection proj = CRSFactory.getCRS("EPSG:" + srid);
65
            if (proj == null) {
66
                throw new ExpressionRuntimeException("Invalid SRID '" + srid + "'.");
67
            }
68
            geom.setProjection(proj);
69
            builder.setGeometry(conn, geom);
70
            byte[] bytes = builder.build();
71
            if (bytes == null) {
72
                this.result();
73
            } else {
74
                this.result(bytes);
75
            }
76
        } catch (Throwable ex) {
77
            throw new SQLException("Can't assign the projection to the geometry", ex);
78
        }
79
    }
80

  
81
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Contains.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_Contains extends Functions.AbstractFunction {
36

  
37
    public ST_Contains(SQLiteConnection conn) {
38
        super("ST_Contains", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes1 = value_blob(0);
45
            if (bytes1 == null) {
46
                this.result();
47
                return;
48
            }
49
            byte[] bytes2 = value_blob(1);
50
            if (bytes2 == null) {
51
                this.result();
52
                return;
53
            }
54
            SQLiteConnection conn = this.getConnection();
55
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
56
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
57
            if (geom1 == null) {
58
                this.result();
59
                return;
60
            }
61
            Geometry geom2 = parser.parseToGeometry(conn, bytes2);
62
            if (geom2 == null) {
63
                this.result();
64
                return;
65
            }
66
            this.result(geom1.contains(geom2) ? 1 : 0);
67
        } catch (Throwable ex) {
68
            throw new SQLException("I can't evaluate if the first geometry contains the second", ex);
69
        }
70
    }
71

  
72
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_CoveredBy.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_CoveredBy extends Functions.AbstractFunction {
36

  
37
    public ST_CoveredBy(SQLiteConnection conn) {
38
        super("ST_CoveredBy", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes1 = value_blob(0);
45
            if (bytes1 == null) {
46
                this.result();
47
                return;
48
            }
49
            byte[] bytes2 = value_blob(1);
50
            if (bytes2 == null) {
51
                this.result();
52
                return;
53
            }
54
            SQLiteConnection conn = this.getConnection();
55
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
56
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
57
            if (geom1 == null) {
58
                this.result();
59
                return;
60
            }
61
            Geometry geom2 = parser.parseToGeometry(conn, bytes2);
62
            if (geom2 == null) {
63
                this.result();
64
                return;
65
            }
66
            this.result(geom1.coveredBy(geom2) ? 1 : 0);
67
        } catch (Throwable ex) {
68
            throw new SQLException("I can't evaluate if the first geometry is covered by the second", ex);
69
        }
70
    }
71

  
72
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Boundary.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Boundary extends Functions.AbstractFunction {
37

  
38
    public ST_Boundary(SQLiteConnection conn) {
39
        super("ST_Boundary", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes = value_blob(0);
46
            if (bytes == null) {
47
                this.result();
48
                return;
49
            }
50
            SQLiteConnection conn = this.getConnection();
51
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
52
            Geometry geom = parser.parseToGeometry(conn,bytes);
53
            if (geom == null) {
54
                this.result();
55
                return;
56
            }
57
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
58
            builder.setGeometry(conn, geom.boundary());
59
            bytes = builder.build();
60
            if (bytes == null) {
61
                this.result();
62
            } else {
63
                this.result(bytes);
64
            }
65

  
66
        } catch (Throwable ex) {
67
            throw new SQLException("Can't get geometry's boundary", ex);
68
        }
69
    }
70

  
71
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Force2D.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Force2D extends Functions.AbstractFunction {
37

  
38
    public ST_Force2D(SQLiteConnection conn) {
39
        super("ST_Force2D", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes = value_blob(0);
46
            if (bytes == null) {
47
                this.result();
48
                return;
49
            }
50
            SQLiteConnection conn = this.getConnection();
51
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
52
            Geometry geom = parser.parseToGeometry(conn,bytes);
53
            if (geom == null) {
54
                this.result();
55
                return;
56
            }
57
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
58
            builder.setGeometry(conn, geom.forceSubtype(Geometry.SUBTYPES.GEOM2D));
59
            bytes = builder.build();
60
            if (bytes == null) {
61
                this.result();
62
            } else {
63
                this.result(bytes);
64
            }
65

  
66
        } catch (Throwable ex) {
67
            throw new SQLException("Can't force to 2D the geometry", ex);
68
        }
69
    }
70

  
71
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Union.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Union extends Functions.AbstractFunction {
37

  
38
    public ST_Union(SQLiteConnection conn) {
39
        super("ST_Union", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes1 = value_blob(0);
46
            if (bytes1 == null) {
47
                this.result();
48
                return;
49
            }
50
            byte[] bytes2 = value_blob(1);
51
            if (bytes2 == null) {
52
                this.result();
53
                return;
54
            }
55
            SQLiteConnection conn = this.getConnection();
56
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
57
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
58
            if (geom1 == null) {
59
                this.result();
60
                return;
61
            }
62
            Geometry geom2 = parser.parseToGeometry(conn, bytes2);
63
            if (geom2 == null) {
64
                this.result();
65
                return;
66
            }
67
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
68
            builder.setGeometry(conn, geom1.union(geom2));
69
            byte[] bytes = builder.build();
70
            if (bytes == null) {
71
                this.result();
72
            } else {
73
                this.result(bytes);
74
            }
75
        } catch (Throwable ex) {
76
            throw new SQLException("Can't build the geometries' union", ex);
77
        }
78
    }
79

  
80
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Difference.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Difference extends Functions.AbstractFunction {
37

  
38
    public ST_Difference(SQLiteConnection conn) {
39
        super("ST_Difference", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes1 = value_blob(0);
46
            if (bytes1 == null) {
47
                this.result();
48
                return;
49
            }
50
            byte[] bytes2 = value_blob(1);
51
            if (bytes2 == null) {
52
                this.result();
53
                return;
54
            }
55
            SQLiteConnection conn = this.getConnection();
56
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
57
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
58
            if (geom1 == null) {
59
                this.result();
60
                return;
61
            }
62
            Geometry geom2 = parser.parseToGeometry(conn, bytes2);
63
            if (geom2 == null) {
64
                this.result();
65
                return;
66
            }
67
            GeopackageGeometryBuilder builder = GeopackageUtils.createGeometryBuilder();
68
            builder.setGeometry(conn, geom1.difference(geom2));
69
            byte[] bytes = builder.build();
70
            if (bytes == null) {
71
                this.result();
72
            } else {
73
                this.result(bytes);
74
            }
75
        } catch (Throwable ex) {
76
            throw new SQLException("Can't build the difference of the geometries", ex);
77
        }
78
    }
79

  
80
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_IsValid.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_IsValid extends Functions.AbstractFunction {
36

  
37
    public ST_IsValid(SQLiteConnection conn) {
38
        super("ST_IsValid", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes = value_blob(0);
45
            if (bytes == null) {
46
                this.result();
47
                return;
48
            }
49
            SQLiteConnection conn = this.getConnection();
50
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
51
            Geometry geom = parser.parseToGeometry(conn,bytes);
52
            if (geom == null) {
53
                this.result();
54
                return;
55
            }
56
            this.result(geom.isValid() ? 1 : 0);
57
        } catch (Throwable ex) {
58
            throw new SQLException("Can't evaluate if the geometry is valid", ex);
59
        }
60
    }
61

  
62
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_NumPoints.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_NumPoints extends Functions.AbstractFunction {
37

  
38
    public ST_NumPoints(SQLiteConnection conn) {
39
        super("ST_NumPoints", conn);
40
    }
41

  
42
    @Override
43
    protected void xFunc() throws SQLException {
44
        try {
45
            byte[] bytes1 = value_blob(0);
46
            if (bytes1 == null) {
47
                this.result();
48
                return;
49
            }
50
            SQLiteConnection conn = this.getConnection();
51
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
52
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
53
            if (geom1 == null) {
54
                this.result();
55
                return;
56
            }
57
            if( geom1 instanceof OrientablePrimitive ) {
58
                this.result(((OrientablePrimitive) geom1).getNumVertices());
59
            }
60
            //FIXME: null or 0 ???
61
            this.result();
62
        } catch (Throwable ex) {
63
            throw new SQLException("I can't get the number of point of the geometry", ex);
64
        }
65
    }
66

  
67
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Perimeter.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
28
import org.sqlite.SQLiteConnection;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ST_Perimeter extends Functions.AbstractFunction {
36

  
37
    public ST_Perimeter(SQLiteConnection conn) {
38
        super("ST_Perimeter", conn);
39
    }
40

  
41
    @Override
42
    protected void xFunc() throws SQLException {
43
        try {
44
            byte[] bytes1 = value_blob(0);
45
            if (bytes1 == null) {
46
                this.result();
47
                return;
48
            }
49
            SQLiteConnection conn = this.getConnection();
50
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
51
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
52
            if (geom1 == null) {
53
                this.result();
54
                return;
55
            }
56
            this.result(geom1.perimeter());
57
        } catch (Throwable ex) {
58
            throw new SQLException("Can't get geometry's perimeter", ex);
59
        }
60
    }
61

  
62
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_SRID.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.cresques.cts.IProjection;
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31

  
32
/**
33
 *
34
 * @author gvSIG Team
35
 */
36
@SuppressWarnings("UseSpecificCatch")
37
public class ST_SRID extends Functions.AbstractFunction {
38

  
39
    public ST_SRID(SQLiteConnection conn) {
40
        super("ST_SRID", conn);
41
    }
42

  
43
    @Override
44
    protected void xFunc() throws SQLException {
45
        try {
46
            byte[] bytes1 = value_blob(0);
47
            if (bytes1 == null) {
48
                this.result();
49
                return;
50
            }
51
            SQLiteConnection conn = this.getConnection();
52
            GeopackageGeometryParser parser = GeopackageUtils.createGeometryParser();
53
            Geometry geom1 = parser.parseToGeometry(conn,bytes1);
54
            if (geom1 == null) {
55
                this.result();
56
                return;
57
            }
58
            
59
            IProjection projection = geom1.getProjection();
60
            if (projection == null) {
61
                this.result(0);
62
                return;
63
            }
64
            String[] x = projection.getAbrev().split(":");
65
            try {
66
                int code = Integer.parseInt(x[1]);
67
                this.result(code);
68
            } catch (Exception ex) {
69
                this.result(-1);
70
            }
71
        } catch (Throwable ex) {
72
            throw new SQLException("Can't get the geometry's projection", ex);
73
        }
74
    }
75

  
76
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/Functions.java
83 83
            new ST_MinY(conn),
84 84
            new ST_GeomFromWKB(conn),
85 85
            new ST_Extent(conn),
86
            new ST_ExtentAggregate(conn)
86
            new ST_ExtentAggregate(conn),
87
                
88
            new ST_Area(conn),
89
            new ST_AsText(conn),
90
            new ST_Boundary(conn),
91
            new ST_Buffer(conn),
92
            new ST_Centroid(conn),
93
            new ST_Contains(conn),
94
            new ST_ConvexHull(conn),
95
            new ST_CoveredBy(conn),
96
            new ST_Covers(conn),
97
            new ST_Crosses(conn),
98
            new ST_Difference(conn),
99
            new ST_Dimension(conn),
100
            new ST_Disjoint(conn),
101
            new ST_EndPoint(conn),
102
            new ST_Envelope(conn),
103
            new ST_Force2D(conn),
104
            new ST_GeometryN(conn),
105
            new ST_GeomFromText(conn),
106
            new ST_Intersection(conn),
107
            new ST_IsSimple(conn),
108
            new ST_IsValid(conn),
109
            new ST_MakePoint(conn),
110
            new ST_NumGeometries(conn),
111
            new ST_NumPoints(conn),
112
            new ST_Overlaps(conn),
113
            new ST_Perimeter(conn),
114
            new ST_Point(conn),
115
            new ST_PointN(conn),
116
            new ST_SetSRID(conn),
117
            new ST_SRID(conn),
118
            new ST_StartPoint(conn),
119
            new ST_Touches(conn),
120
            new ST_Transform(conn),
121
            new ST_Union(conn),
122
            new ST_Within(conn),
123
            new ST_X(conn),
124
            new ST_Y(conn),
125
            new ST_Z(conn)
87 126
        };
88 127

  
89 128
        for (Function function : functions) {
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/functions/ST_Intersection.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.sqlite.dal.functions;
23

  
24
import java.sql.SQLException;
25
import org.gvsig.fmap.geom.Geometry;
26
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryBuilder;
27
import org.gvsig.sqlite.dal.geopackage.GeopackageGeometryParser;
28
import org.gvsig.sqlite.dal.geopackage.GeopackageUtils;
29
import org.sqlite.SQLiteConnection;
30

  
31
/**
32
 *
33
 * @author gvSIG Team
34
 */
35
@SuppressWarnings("UseSpecificCatch")
36
public class ST_Intersection extends Functions.AbstractFunction {
37

  
38
    public ST_Intersection(SQLiteConnection conn) {
39
        super("ST_Intersection", conn);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff