~ubuntu-branches/ubuntu/trusty/postgis/trusty-security

« back to all changes in this revision

Viewing changes to lwgeom/lwmline.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2009-12-11 13:10:34 UTC
  • mfrom: (1.1.9 upstream) (5.2.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20091211131034-wmsz69wxvt95pe5r
Tags: 1.4.0-2
* Upload to unstable.
* Better parameterized debian/rules against postgis $(VERSION).
* Added dblatex and libcunit1-dev among build-deps.
* Added postgis_comments.sql to contrib/ SQL templates.
* Dropping 8.3 support, no more supported for squeeze.
  (closes: #559587)
* Do not stop on error in postrm if the target dir does not exist.
  (closes: #560409)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
 * $Id: lwmline.c 2369 2006-05-30 08:38:58Z strk $
3
 
 *
4
 
 * PostGIS - Spatial Types for PostgreSQL
5
 
 * http://postgis.refractions.net
6
 
 * Copyright 2001-2006 Refractions Research Inc.
7
 
 *
8
 
 * This is free software; you can redistribute and/or modify it under
9
 
 * the terms of the GNU General Public Licence. See the COPYING file.
10
 
 * 
11
 
 **********************************************************************/
12
 
 
13
 
#include <stdio.h>
14
 
#include <stdlib.h>
15
 
#include <string.h>
16
 
#include "liblwgeom.h"
17
 
 
18
 
LWMLINE *
19
 
lwmline_deserialize(uchar *srl)
20
 
{
21
 
        LWMLINE *result;
22
 
        LWGEOM_INSPECTED *insp;
23
 
        int type = lwgeom_getType(srl[0]);
24
 
        int i;
25
 
 
26
 
        if ( type != MULTILINETYPE ) 
27
 
        {
28
 
                lwerror("lwmline_deserialize called on NON multiline: %d",
29
 
                        type);
30
 
                return NULL;
31
 
        }
32
 
 
33
 
        insp = lwgeom_inspect(srl);
34
 
 
35
 
        result = lwalloc(sizeof(LWMLINE));
36
 
        result->type = insp->type;
37
 
        result->SRID = insp->SRID;
38
 
        result->ngeoms = insp->ngeometries;
39
 
        result->geoms = lwalloc(sizeof(LWLINE *)*insp->ngeometries);
40
 
 
41
 
        if (lwgeom_hasBBOX(srl[0]))
42
 
        {
43
 
                result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
44
 
                memcpy(result->bbox, srl+1, sizeof(BOX2DFLOAT4));
45
 
        }
46
 
        else result->bbox = NULL;
47
 
 
48
 
 
49
 
        for (i=0; i<insp->ngeometries; i++)
50
 
        {
51
 
                result->geoms[i] = lwline_deserialize(insp->sub_geoms[i]);
52
 
                if ( TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type) )
53
 
                {
54
 
                        lwerror("Mixed dimensions (multiline:%d, line%d:%d)",
55
 
                                TYPE_NDIMS(result->type), i,
56
 
                                TYPE_NDIMS(result->geoms[i]->type)
57
 
                        );
58
 
                        return NULL;
59
 
                }
60
 
        }
61
 
 
62
 
        return result;
63
 
}
64
 
 
65
 
/*
66
 
 * Add 'what' to this multiline at position 'where'.
67
 
 * where=0 == prepend
68
 
 * where=-1 == append
69
 
 * Returns a MULTILINE or a COLLECTION
70
 
 */
71
 
LWGEOM *
72
 
lwmline_add(const LWMLINE *to, uint32 where, const LWGEOM *what)
73
 
{
74
 
        LWCOLLECTION *col;
75
 
        LWGEOM **geoms;
76
 
        int newtype;
77
 
        uint32 i;
78
 
 
79
 
        if ( where == -1 ) where = to->ngeoms;
80
 
        else if ( where < -1 || where > to->ngeoms )
81
 
        {
82
 
                lwerror("lwmline_add: add position out of range %d..%d",
83
 
                        -1, to->ngeoms);
84
 
                return NULL;
85
 
        }
86
 
 
87
 
        /* dimensions compatibility are checked by caller */
88
 
 
89
 
        /* Construct geoms array */
90
 
        geoms = lwalloc(sizeof(LWGEOM *)*(to->ngeoms+1));
91
 
        for (i=0; i<where; i++)
92
 
        {
93
 
                geoms[i] = lwgeom_clone((LWGEOM *)to->geoms[i]);
94
 
        }
95
 
        geoms[where] = lwgeom_clone(what);
96
 
        for (i=where; i<to->ngeoms; i++)
97
 
        {
98
 
                geoms[i+1] = lwgeom_clone((LWGEOM *)to->geoms[i]);
99
 
        }
100
 
 
101
 
        if ( TYPE_GETTYPE(what->type) == LINETYPE ) newtype = MULTILINETYPE;
102
 
        else newtype = COLLECTIONTYPE;
103
 
 
104
 
        col = lwcollection_construct(newtype,
105
 
                to->SRID, NULL,
106
 
                to->ngeoms+1, geoms);
107
 
        
108
 
        return (LWGEOM *)col;
109
 
 
110
 
}