Пример #1
0
def readTestFonts():
    import os

    fonts = []
    for fontName in ['ArialMT.svg', 'Helvetica-Regular.svg']:
        log.openSection("Loading font %s into database..." % fontName)
        font = SVGFontReader(
            os.path.dirname(__file__) + os.sep + fontName,
            addCharaters(getLowerASCII(), u'ěščřžýáíéúůĚŠČŘŽÝÁÍÉÚŮ'))
        fonts.append(font)
        log.info("'%s':%d glyphs readed." %
                 (fontName, len(font.glyphs.keys())))
        log.info("[%s]" % font.letters)
        log.closeSection()

    return fonts
Пример #2
0
def getWFSData(databaseName, tableName, bbox, srsName, schemaName="", sqlQuery=""):
    from shapely.wkb import loads
    import geojson

    import pygeotoolbox.sharedtools.log as logger
    from pygeotoolbox.database import databaseByName
    from pygeotoolbox.sharedtools import listToSqlStr

    logger.openSection("Building WFS Data...")
    FIELD_DEFS = 'graphic_symbol'
    GEOMETRY_FIELD_NAME = 'geom'

    """
    sampleRequest:
    http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/hidden/MapGen/osm_lund.map&service=wfs&version=1.1.0&request=GetFeature&typename=data_area&outputFormat=application/json&srsname=EPSG:3857&bbox=1471006.5443115234,7501014.372741699,1471356.5870361328,7502471.5505981445,EPSG:3857

    """
    if not schemaName:
        schemaName = "mg_work"

    if __SYMBOLNAMES:
        symbolNamesWhereClause = "graphic_symbol in %s and " % listToSqlStr(__SYMBOLNAMES)
    else:
        symbolNamesWhereClause = ""
    logger.info("Symbol names:" + str(listToSqlStr(__SYMBOLNAMES)))
    logger.info("bbox:" + str(bbox))
    sql = "select %s, (st_dump(%s)).geom from %s.%s, (select ST_MakeEnvelope(%s) as envelope) as bbox where %s %s && bbox.envelope" % (FIELD_DEFS, GEOMETRY_FIELD_NAME, schemaName, tableName, bbox, symbolNamesWhereClause, GEOMETRY_FIELD_NAME)
    if sqlQuery:
        sql += " and (%s)" % sqlQuery

    fieldNames = FIELD_DEFS.split(',')

    logger.info("Loading features...")
    features = []
    database = databaseByName(databaseName)
    for row in database.executeSelectSQL(sql):
        shape = loads(row[len(row) - 1], hex=True)
        properties = {}
        for fieldName, fieldIndex in zip(fieldNames, range(len(fieldNames))):
            properties[fieldName] = row[fieldIndex]

        if __DUMP_SYMBOLS_PROC:
            features.extend(__DUMP_SYMBOLS_PROC(shape, properties))
        else:
            features.append(geojson.Feature(geometry=shape, properties=properties))
    logger.info("%d features found" % len(features))
    logger.closeSection()
    return '{ "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::%s" } }, ' % srsName + geojson.dumps(geojson.FeatureCollection(features))[1:]
Пример #3
0
    def __init__(self, templateFileName):
        from pygeotoolbox.sharedtools import fileToStr, log

        log.openSection("Reading HTML Templates from '%s'" % templateFileName)
        self.templates = {}
        templatesContent = fileToStr(templateFileName)
        searchPos = 0
        while True:
            templateEndMarker_StartPos = templatesContent.find("<!-- END OF ", searchPos)
            if templateEndMarker_StartPos >= 0:
                templateEndMarker_EndPos = templatesContent.find("-->", templateEndMarker_StartPos)
                templateName = templatesContent[templateEndMarker_StartPos+12:templateEndMarker_EndPos].strip()
                templateStartMarker_StartPos = templatesContent.find("<!-- %s -->" % templateName, searchPos)
                if templateStartMarker_StartPos>=0:
                    templateContent = templatesContent[templateStartMarker_StartPos+len(templateName)+9:templateEndMarker_StartPos]
                    self.templates[templateName] = templateContent
                else:
                    log.error("'%s' not found" % "<!-- %s -->" % templateName)
                searchPos = templateEndMarker_EndPos + 3
            else:
                break

        log.info("Template names:%s (HTMLTemplateProcessor)" % str(self.templates.keys()))
        log.closeSection()
Пример #4
0
        if isinstance(svgReaderOrSVGFileName, SVGFontReader):
            svgFontReader = svgReaderOrSVGFileName
        else:
            svgFontReader = SVGFontReader(svgReaderOrSVGFileName,
                                          charsToBeLoaded=None)
        self.glyphs = svgFontReader.glyphs
        self.name = svgFontReader.name
        if saveToDatabase:
            self.saveToDatabase()


if __name__ == "__main__":
    from svg.svgfontreader import readTestFonts

    log.openSection("Reading svg fonts...")
    fonts = readTestFonts()
    log.closeSection()

    log.openSection("Saving fonts to database...")
    for svgFont in readTestFonts():
        log.info(svgFont.name)
        font = Font("")
        font.readFromSVG(svgFont)
        log.closeSection()
    log.closeSection()

# @TODO Některé základní znaky se načtou, ale nemají glyph
# @TODO Sloupce unicode a letters se nenaplňují
# @TODO Potřeba vytvořit algoritmus pro sestavení textu podél křivky či čáry, s volbou text originu, případných offsetů atd.
Пример #5
0
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument("--svgFileName", help="SVF Font file name")
    parser.add_argument("--sqlSelect", help="Sql select for needed chars")
    parser.add_argument("--readASCII127",
                        help="Force enable reading ASCII Base characters",
                        action="store_true")
    parser.add_argument("--buildLettersRowSQL", action="store_true")

    args = parser.parse_args()

    charsToBeLoaded = None
    # --sqlSelect "select name from osm_query.roads where name is not null group by name order by name;"
    if args.sqlSelect:
        log.info('Reading characters from sql "%s"' % args.sqlSelect)
        charsToBeLoaded = getCharactersInSQL(args.sqlSelect)
        log.info("charsToBeLoaded:[%s]" % charsToBeLoaded)

    # --readASCII127
    if charsToBeLoaded and args.readASCII127:
        log.info("Adding ASCII 127 characters...")
        charsToBeLoaded = addCharaters(charsToBeLoaded, getLowerASCII())
        log.info("charsToBeLoaded:[%s]" % charsToBeLoaded)

    charsToBeLoaded = addCharaters(charsToBeLoaded, getLongerASCII())

    #--svgFileName Helvetica-Regular.svg
    #--svgFileName ArialMT.svg
    font = SVGFontReader(args.svgFileName, charsToBeLoaded)