Esempio n. 1
0
def gen_point(min_x=-180,
              min_y=-90,
              max_x=190,
              max_y=90,
              min_z=None,
              max_z=None,
              granularity=1000,
              srid=4326):
    """
    Generates a random point with x, y, optional z and a SRID.
    Only coordinates are random, SRID is fixed by user.
    granularity specifies the precision of the generated coordinates
    (1000 by default for 0.001 as smallest diff).
    """

    x = gen_integer(int(min_x * granularity), int(
        max_x * granularity)) / float(granularity)
    y = gen_integer(int(min_y * granularity), int(
        max_y * granularity)) / float(granularity)

    if min_z is not None and max_z is not None:
        z = gen_integer(int(min_z * granularity), int(
            max_z * granularity)) / float(granularity)
        return Point(x=x, y=y, z=z, srid=srid)

    return Point(x=x, y=y, srid=srid)
 def prepare_model(self, cls, identity=True, optional=True, **attrs):
     default = dict(
         _fill_optional=optional
     )
     if identity:
         default.update(id=gen_integer(min_int=1))
     return mommy.prepare(cls, **dict(default, **attrs))
def gen_point(min_x=-180, min_y=-90, max_x=190, max_y=90, min_z=None, max_z=None, granularity=1000, srid=4326):

    """
    Generates a random point with x, y, optional z and a SRID.
    Only coordinates are random, SRID is fixed by user.
    granularity specifies the precision of the generated coordinates
    (1000 by default for 0.001 as smallest diff).
    """

    x = gen_integer(int(min_x * granularity), int(max_x * granularity)) / float(granularity)
    y = gen_integer(int(min_y * granularity), int(max_y * granularity)) / float(granularity)

    if min_z is not None and max_z is not None:
        z = gen_integer(int(min_z * granularity), int(max_z * granularity)) / float(granularity)
        return Point(x=x, y=y, z=z, srid=srid)

    return Point(x=x, y=y, srid=srid)
def gen_point(min_x=-180,
              min_y=-90,
              max_x=190,
              max_y=90,
              min_z=None,
              max_z=None,
              srid=4326):

    """Generates a random point with x, y, optional z and a SRID. Only coordinates are random, SRID is fixed by user."""

    x = random() * gen_integer(min_x, max_x)
    y = random() * gen_integer(min_y, max_y)

    if min_z is not None and max_z is not None:
        z = random() * gen_integer(min_z, max_z)
        return Point(x=x, y=y, z=z, srid=srid)

    return Point(x=x, y=y, srid=srid)
def gen_rectangular_multipolygon(min_x=-1, min_y=-1, max_x=1, max_y=1, min_polys=1, max_polys=2, srid=4326):

    """Generates a multipolygon, based on minxy and maxxy."""
    return MultiPolygon(
        [
            gen_rectangular_polygon(min_x, min_y, max_x, max_y, srid)
            for i in range(gen_integer(min_polys, max_polys + 1))
        ]
    )
Esempio n. 6
0
def gen_rectangular_multipolygon(min_x=-1,
                                 min_y=-1,
                                 max_x=1,
                                 max_y=1,
                                 min_polys=1,
                                 max_polys=2,
                                 srid=4326):
    """Generates a multipolygon, based on minxy and maxxy."""
    return MultiPolygon([
        gen_rectangular_polygon(min_x, min_y, max_x, max_y, srid)
        for i in range(gen_integer(min_polys, max_polys + 1))
    ])
 def prepare_model(self, cls, identity=True, optional=True, **attrs):
     default = dict(_fill_optional=optional)
     if identity:
         default.update(id=gen_integer(min_int=1))
     return mommy.prepare(cls, **dict(default, **attrs))
 def gen_commaseparated_ingeters(max_length):
     return ','.join(str(generators.gen_integer(1, 9))
                     for x in six.moves.range(1, max_length // 2))
try:
    from model_mommy import generators
except ImportError:  # model_mommy is not installed
    MODEL_MOMMY_MAPPING = {}
else:

    def gen_commaseparated_ingeters(max_length):
        return ','.join(str(generators.gen_integer(1, 9))
                        for x in six.moves.range(1, max_length // 2))
    gen_commaseparated_ingeters.required = ['max_length']

    MODEL_MOMMY_MAPPING = {
        StrictBooleanField: generators.gen_boolean,
        StrictBigIntegerField: generators.gen_integer,
        StrictCharField: generators.gen_string,
        StrictCommaSeparatedIntegerField: gen_commaseparated_ingeters,
        StrictDateField: generators.gen_date,
        StrictDateTimeField: generators.gen_datetime,
        StrictDecimalField: generators.gen_decimal,
        StrictEmailField: generators.gen_email,
        StrictTimeField: generators.gen_time,
        StrictSmallIntegerField: lambda: generators.gen_integer(-32768, 32767),
        StrictPositiveSmallIntegerField: lambda: generators.gen_integer(0, 32767),
        StrictIntegerField: lambda: generators.gen_integer(-2147483648, 2147483647),
        StrictPositiveIntegerField: lambda: generators.gen_integer(0, 2147483647),
        StrictURLField: generators.gen_url,
        StrictSlugField: generators.gen_slug,
        StrictFloatField: generators.gen_float,
        StrictTextField: generators.gen_text,
    }
def gen_multilinestring(number_of_points=2,
                        min_x=-180,
                        min_y=-90,
                        max_x=180,
                        max_y=90,
                        min_z=None,
                        max_z=None,
                        min_linestrings=1,
                        max_linestrings=2,
                        srid=4326):

  return MultiPolygon([gen_linestring(min_x, min_y, max_x, max_y, srid) for i in range(gen_integer(min_linestrings, max_linestrings+1))])