<commit_before>
# -*- coding: utf-8 -*-
"""Vector related Classes and Functions

    author: <NAME>

    changlog:

     - 12-04-12 jz - origin version
     - 16-07-01 lj - reorganized for pygeoc
     - 17-06-25 lj - check by pylint and reformat by Google style
"""
from __future__ import absolute_import, unicode_literals
import os
import sys

from osgeo.ogr import CreateGeometryFromJson as ogr_CreateGeometryFromJson
from osgeo.ogr import Feature as ogr_Feature
from osgeo.ogr import Geometry as ogr_Geometry
from osgeo.ogr import GetDriverByName as ogr_GetDriverByName
from osgeo.ogr import wkbLineString, OFTInteger
from osgeo.osr import SpatialReference as osr_SpatialReference
from osgeo.ogr import FieldDefn as ogr_FieldDefn
import gdal

from pygeoc.utils import FileClass, UtilClass, sysstr


class VectorUtilClass(object):
    """Utility function to handle vector data."""

    def __init__(self):
        pass

    @staticmethod
    def raster2shp(rasterfile, vectorshp, layername=None, fieldname=None,
                   band_num=1, mask='default'):
        """Convert raster to ESRI shapefile"""
        FileClass.remove_files(vectorshp)
        FileClass.check_file_exists(rasterfile)
        # this allows GDAL to throw Python Exceptions
        gdal.UseExceptions()
        src_ds = gdal.Open(rasterfile)
        if src_ds is None:
            print('Unable to open %s' % rasterfile)
            sys.exit(1)
        try:
            srcband = src_ds.GetRasterBand(band_num)
        except RuntimeError as e:
            # for example, try GetRasterBand(10)
            print('Band ( %i ) not found, %s' % (band_num, e))
            sys.exit(1)<commit_msg>Typo fixed: from osgeo import gdal<commit_after>
# -*- coding: utf-8 -*-
"""Vector related Classes and Functions

    author: <NAME>

    changlog:

     - 12-04-12 jz - origin version
     - 16-07-01 lj - reorganized for pygeoc
     - 17-06-25 lj - check by pylint and reformat by Google style
"""
from __future__ import absolute_import, unicode_literals
import os
import sys

from osgeo.ogr import CreateGeometryFromJson as ogr_CreateGeometryFromJson
from osgeo.ogr import Feature as ogr_Feature
from osgeo.ogr import Geometry as ogr_Geometry
from osgeo.ogr import GetDriverByName as ogr_GetDriverByName
from osgeo.ogr import wkbLineString, OFTInteger
from osgeo.osr import SpatialReference as osr_SpatialReference
from osgeo.ogr import FieldDefn as ogr_FieldDefn
from osgeo import gdal

from pygeoc.utils import FileClass, UtilClass, sysstr


class VectorUtilClass(object):
    """Utility function to handle vector data."""

    def __init__(self):
        pass

    @staticmethod
    def raster2shp(rasterfile, vectorshp, layername=None, fieldname=None,
                   band_num=1, mask='default'):
        """Convert raster to ESRI shapefile"""
        FileClass.remove_files(vectorshp)
        FileClass.check_file_exists(rasterfile)
        # this allows GDAL to throw Python Exceptions
        gdal.UseExceptions()
        src_ds = gdal.Open(rasterfile)
        if src_ds is None:
            print('Unable to open %s' % rasterfile)
            sys.exit(1)
        try:
            srcband = src_ds.GetRasterBand(band_num)
        except RuntimeError as e:
            # for example, try GetRasterBand(10)
            print('Band ( %i ) not found, %s' % (band_num, e))
            sys.exit(1)
{'fraction_non_alphanumeric': 0.07735625370480143, 'fraction_numerical': 0.014819205690574985, 'mean_word_length': 2.961267605633803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4691964', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1017, 'n_words': 312}