File: python.txt

package info (click to toggle)
mapserver 4.10.0-5.1%2Betch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,264 kB
  • ctags: 15,165
  • sloc: ansic: 164,837; sh: 6,141; python: 5,770; java: 5,169; perl: 2,388; cpp: 1,603; makefile: 735; lex: 507; yacc: 317; tcl: 158; cs: 85; ruby: 53
file content (190 lines) | stat: -rw-r--r-- 5,520 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
..  $Id: python.txt,v 1.9 2004/11/14 00:44:42 sean Exp $
    
    This is the new unified mapscript documentation prepared using
    reStructured Text.

    ***************************************************************
    RULE #1: No tabs in this document!
    RULE #2: Indent is 4 characters.
    RULE #3: There is no rule 3.

    Thank you.
    ***************************************************************
    
    reStructured Text is part of the Python docutils module
    
        http://docutils.sourceforge.net/
    
    Documentation on reStructured Text is found at

        http://docutils.sourceforge.net/rst.html

    First reST note is about comments: a double period begins a comment
    block (like a /* in C) and a double period on a line all by itself
    closes the comment block.
..

..  Below is our main heading (becomes H1).  Note that we require empty
    lines between every different reST element such as the empty line
    between the end of this comment and the begining of the heading.
..

*****************************************************************************
 Python Appendix
*****************************************************************************

:Author: Sean Gillies
:Contact: sgillies@frii.com
:Revision: $Revision: 1.9 $
:Date: $Date: 2004/11/14 00:44:42 $

..  The next heading encountered becomes our H2
..

.. sectnum::

.. contents::
    :depth: 2
    :backlinks: top

=============================================================================
 Introduction
=============================================================================

The Python mapscript module contains some class extension methods that have
not yet been implemented for other languages.

=============================================================================
 Classes
=============================================================================

References to sections below will be added here as the documentation grows.

-----------------------------------------------------------------------------
 imageObj
-----------------------------------------------------------------------------

The Python Imaging Library, http://www.pythonware.com/products/pil/, is an
indispensible tool for image manipulation.  The extensions to imageObj are
all geared towards better integration of PIL in mapscript applications.

imageObj Methods
----------------

imageObj( PyObject arg1, PyObject arg2 [, PyObject arg3 ] ) : imageObj_
    Create a new instance which is either empty or read from a Python
    file-like object that refers to a GD format image.
    
    The constructor has 2 different modes.  In the blank image mode, arg1
    and arg2 should be the desired width and height in pixels, and the 
    optional arg3 should be either an instance of outputFormatObj or
    a GD driver name as a shortcut to a format.  In the image file mode,
    arg1 should be a filename or a Python file or file-like object.  If
    the file-like object does not have a "seek" attribute (such as a
    urllib resource handle), then a GD driver name *must* be provided as
    arg2.
    
    Here's an example of creating a 320 pixel wide by 240 pixel high JPEG
    using the constructor's blank image mode::

        image = mapscript.imageObj(320, 240, 'GD/JPEG')
        
    In image file mode, interesting values of *arg1* to try are instances
    of *StringIO*::

        s = StringIO()
        pil_image.save(s)    # Save an image manipulated with PIL
        ms_image = imageObj(s)

    Or the file-like object returned from *urlopen*

    ::
        
        url = urllib.urlopen('http://mapserver.gis.umn.edu/bugs/ant.jpg')
        ms_image = imageObj(url, 'GD/JPEG')


write( [ PyObject file ] ) : void
    Write image data to a Python file-like object.  Default is stdout.

------------------------------------------------------------------------------
 pointObj
------------------------------------------------------------------------------

pointObj Methods
----------------

__str__() : string
    Return a string formatted like

    ::

        { 'x': %f , 'y': %f }

    
    with the coordinate values substituted appropriately.  Usage example:

    ::

        >>> p = mapscript.pointObj(1, 1)
        >>> str(p)
        { 'x': 1.000000 , 'y': 1.000000 }


    Note that the return value can be conveniently eval'd into a Python
    dictionary:

    ::

        >>> p_dict = eval(str(p))
        >>> p_dict['x']
        1.000000


------------------------------------------------------------------------------
 rectObj
------------------------------------------------------------------------------

rectObj Methods
---------------

__contains__( pointObj point ) : boolean
    Returns True if *point* is inside the rectangle, otherwise returns False.

    ::

        >>> r = mapscript.rectObj(0, 0, 1, 1)
        >>> p = mapscript.pointObj(2, 0)       # outside
        >>> p in r
        False
        >>> p not in r
        True

    
__str__() : string
    Return a string formatted like

    ::

        { 'minx': %f , 'miny': %f , 'maxx': %f , 'maxy': %f }

    
    with the bounding values substituted appropriately.  Usage example:

    ::

        >>> r = mapscript.rectObj(0, 0, 1, 1)
        >>> str(r)
        { 'minx': 0.000000 , 'miny': 0.000000 , 'maxx': 1.000000 , 'maxy': 1.000000 }


    Note that the return value can be conveniently eval'd into a Python
    dictionary:

    ::

        >>> r_dict = eval(str(r))
        >>> r_dict['minx']
        0.000000