Skip to content

Commit

Permalink
Fix eol of mapscript python examples to LF instead of CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jun 12, 2020
1 parent 1036f98 commit 16eb9de
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 336 deletions.
144 changes: 72 additions & 72 deletions mapscript/python/examples/project_csv.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
#!/usr/bin/env python

"""
Simple example to read a csv file and reproject point x/y data
Usage:
project_csv.py cities.csv 2 1 EPSG:4326 EPSG:3857
"""

import sys
import csv
from io import open
import mapscript


def main(input_file, x_field_idx, y_field_idx, input_proj, output_proj):

# set input and output projections
proj_in = mapscript.projectionObj(input_proj)
proj_out = mapscript.projectionObj(output_proj)

# open file
with open(input_file, encoding='utf-8') as f:
# read csv
csv_in = csv.reader(f)
headers = next(csv_in)

# setup output
csv_out = csv.writer(sys.stdout)
csv_out.writerow(headers)

for row in csv_in:
# set pointObj
point = mapscript.pointObj(float(row[x_field_idx]), float(row[y_field_idx]))
# project
point.project(proj_in, proj_out)

# update with reprojected coordinates
row[x_field_idx] = point.x
row[y_field_idx] = point.y

csv_out.writerow(row)


def usage():
"""
Display usage if program is used incorrectly
"""
print("Syntax: %s <csvfile> <x_col> <y_col> <epsg_code_in> <epsg_code_out>" % sys.argv[0])
sys.exit(2)


# check input parameters

if (len(sys.argv) != 6):
usage()


input_file = sys.argv[1]

# set x and y indices

x_field_idx = int(sys.argv[2])
y_field_idx = int(sys.argv[3])

# get projection codes

input_proj = "init="+sys.argv[4].lower()
output_proj = "init="+sys.argv[5].lower()
main(input_file, x_field_idx, y_field_idx, input_proj, output_proj)
#!/usr/bin/env python

"""
Simple example to read a csv file and reproject point x/y data
Usage:
project_csv.py cities.csv 2 1 EPSG:4326 EPSG:3857
"""

import sys
import csv
from io import open
import mapscript


def main(input_file, x_field_idx, y_field_idx, input_proj, output_proj):

# set input and output projections
proj_in = mapscript.projectionObj(input_proj)
proj_out = mapscript.projectionObj(output_proj)

# open file
with open(input_file, encoding='utf-8') as f:
# read csv
csv_in = csv.reader(f)
headers = next(csv_in)

# setup output
csv_out = csv.writer(sys.stdout)
csv_out.writerow(headers)

for row in csv_in:
# set pointObj
point = mapscript.pointObj(float(row[x_field_idx]), float(row[y_field_idx]))
# project
point.project(proj_in, proj_out)

# update with reprojected coordinates
row[x_field_idx] = point.x
row[y_field_idx] = point.y

csv_out.writerow(row)


def usage():
"""
Display usage if program is used incorrectly
"""
print("Syntax: %s <csvfile> <x_col> <y_col> <epsg_code_in> <epsg_code_out>" % sys.argv[0])
sys.exit(2)


# check input parameters

if (len(sys.argv) != 6):
usage()


input_file = sys.argv[1]

# set x and y indices

x_field_idx = int(sys.argv[2])
y_field_idx = int(sys.argv[3])

# get projection codes

input_proj = "init="+sys.argv[4].lower()
output_proj = "init="+sys.argv[5].lower()
main(input_file, x_field_idx, y_field_idx, input_proj, output_proj)
188 changes: 94 additions & 94 deletions mapscript/python/examples/shpdump.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
#!/usr/bin/env python

"""
Dump the contents of the passed in Shapefile
Usage:
python shpdump.py polygon.shp
"""

import mapscript
import sys
import os


def plural(x):
"""
Returns an 's' if plural
Useful in print statements to avoid something like 'point(s)'
"""
if x > 1:
return 's'
return ''


def get_shapefile_object(sf_path):

# make sure can access .shp file, create shapefileObj

if os.access(sf_path, os.F_OK):
sf_obj = mapscript.shapefileObj(sf_path, -1)
else:
print("Can't access {}".format(sf_path))
sys.exit(2)

return sf_obj


def main(sf_path):

if not sf_path.lower().endswith(".shp"):
sf_path += ".shp"

sf_obj = get_shapefile_object(sf_path)

# create an empty Shapefile object

s_obj = mapscript.shapeObj()

# loop through each shape in the original Shapefile

for i in range(sf_obj.numshapes):

# get the object at index i
sf_obj.get(i, s_obj)
print("Shape %i has %i part%s" % (i, s_obj.numlines, plural(s_obj.numlines)))
print("Bounds (%f, %f) (%f, %f)" % (s_obj.bounds.minx, s_obj.bounds.miny, s_obj.bounds.maxx, s_obj.bounds.maxy))

# loop through parts of each shape

for j in range(s_obj.numlines):

# get the jth part of the ith object

part = s_obj.get(j)
print("Part %i has %i point%s" % (j, part.numpoints, plural(part.numpoints)))

# loop through points in each part

for k in range(part.numpoints):

# get the kth point of the jth part of the ith shape

point = part.get(k)
print("%i: %f, %f" % (k, point.x, point.y))


def usage():
"""
Display usage if program is used incorrectly
"""
print("Syntax: %s <shapefile_path>" % sys.argv[0])
sys.exit(2)


# make sure passing in filename argument
if len(sys.argv) != 2:
usage()


sf_path = sys.argv[1]
main(sf_path)
#!/usr/bin/env python

"""
Dump the contents of the passed in Shapefile
Usage:
python shpdump.py polygon.shp
"""

import mapscript
import sys
import os


def plural(x):
"""
Returns an 's' if plural
Useful in print statements to avoid something like 'point(s)'
"""
if x > 1:
return 's'
return ''


def get_shapefile_object(sf_path):

# make sure can access .shp file, create shapefileObj

if os.access(sf_path, os.F_OK):
sf_obj = mapscript.shapefileObj(sf_path, -1)
else:
print("Can't access {}".format(sf_path))
sys.exit(2)

return sf_obj


def main(sf_path):

if not sf_path.lower().endswith(".shp"):
sf_path += ".shp"

sf_obj = get_shapefile_object(sf_path)

# create an empty Shapefile object

s_obj = mapscript.shapeObj()

# loop through each shape in the original Shapefile

for i in range(sf_obj.numshapes):

# get the object at index i
sf_obj.get(i, s_obj)
print("Shape %i has %i part%s" % (i, s_obj.numlines, plural(s_obj.numlines)))
print("Bounds (%f, %f) (%f, %f)" % (s_obj.bounds.minx, s_obj.bounds.miny, s_obj.bounds.maxx, s_obj.bounds.maxy))

# loop through parts of each shape

for j in range(s_obj.numlines):

# get the jth part of the ith object

part = s_obj.get(j)
print("Part %i has %i point%s" % (j, part.numpoints, plural(part.numpoints)))

# loop through points in each part

for k in range(part.numpoints):

# get the kth point of the jth part of the ith shape

point = part.get(k)
print("%i: %f, %f" % (k, point.x, point.y))


def usage():
"""
Display usage if program is used incorrectly
"""
print("Syntax: %s <shapefile_path>" % sys.argv[0])
sys.exit(2)


# make sure passing in filename argument
if len(sys.argv) != 2:
usage()


sf_path = sys.argv[1]
main(sf_path)

0 comments on commit 16eb9de

Please sign in to comment.