Пример #1
0
def get_shp_centroid(shp_points):
    from shapely.geometry import Polygon

    centroid = Polygon(shp_points).centroid.wkt
    clon, clat = centroid.strip('PIONT').replace('(',
                                                 ' ').replace(')',
                                                              ' ').split()

    return float(clon), float(clat)
Пример #2
0
def labelpolygon(m, plt, sf, field, **kwargs):
    '''
    fstyle  = ['normal', 'italic', 'oblique']
    fweight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
    '''

    from shapely.geometry import Polygon
    from mapping_tools import get_field_index
    import matplotlib as mpl

    mpl.rcParams['pdf.fonttype'] = 42

    xoff = 0.
    yoff = 0.
    fsize = 10
    col = 'k'
    fstyle = 'normal'
    fweight = 'normal'
    value = None
    for key in ('xoff', 'yoff', 'fsize', 'fweight', 'col', 'fstyle', 'value'):
        if key in kwargs:
            if key == 'xoff':
                xoff = kwargs[key]
            if key == 'yoff':
                yoff = kwargs[key]
            if key == 'fsize':
                fsize = kwargs[key]
            if key == 'fweight':
                fweight = kwargs[key]
            if key == 'fstyle':
                fstyle = kwargs[key]
            if key == 'col':
                col = kwargs[key]
            if key == 'value':
                value = kwargs[key]

    shapes = sf.shapes()
    recs = sf.records()

    # get field index
    findex = get_field_index(sf, field)

    for i, shape in enumerate(shapes):
        centroid = Polygon(shape.points).centroid.wkt
        centroid = centroid.strip('PIONT').replace('(',
                                                   ' ').replace(')',
                                                                ' ').split()
        tx, ty = m(float(centroid[0]), float(centroid[1]))
        if tx > m.xmin and tx < m.xmax and ty > m.ymin and ty < m.ymax:
            if value == None or value == recs[i][findex]:
                plt.text(tx + xoff, ty + yoff, recs[i][findex], size=fsize, \
                         weight=fweight, color=col, style=fstyle, va='center', ha='center')
        '''
Пример #3
0
##########################################################################################
# get average per zone and plot
##########################################################################################

src_codes = get_field_data(sfz, 'CODE', 'str')
src_shapes = sfz.shapes()

av_shmax, sig_shmax = get_aus_shmax_vectors(src_codes, src_shapes)

# get centroid and plot
alen = 180000
head_length = 60000

for i, shape in enumerate(src_shapes):
    centroid = Polygon(shape.points).centroid.wkt
    centroid = centroid.strip('PIONT').replace('(', ' ').replace(')',
                                                                 ' ').split()
    cx, cy = m(float(centroid[0]), float(centroid[1]))

    dy = alen * cos(radians(av_shmax[i])) + head_length * cos(
        radians(av_shmax[i]))
    dx = alen * sin(radians(av_shmax[i])) + head_length * sin(
        radians(av_shmax[i]))
    ax.arrow(cx - dx,
             cy - dy,
             dx,
             dy,
             head_width=60000,
             head_length=head_length,
             lw=2.,
             ec='maroon',
             fc='maroon',