def getGeometryFromDayHour(dayField, hourField, proportionX, proportionY):
    cal = Calendar.getInstance()
    cal.setTime(dayField)
    y = cal.get(Calendar.DAY_OF_WEEK)
    interChangeToOrderRange = {Calendar.MONDAY:0,
          Calendar.TUESDAY:1,
          Calendar.WEDNESDAY:2,
          Calendar.THURSDAY:3,
          Calendar.FRIDAY:4,
          Calendar.SATURDAY:5,
          Calendar.SUNDAY:6
          }
    yf = interChangeToOrderRange[y] * proportionY
    
    
    cal = Calendar.getInstance()
    cal.setTime(hourField)
    h = cal.get(Calendar.HOUR_OF_DAY)
    m = cal.get(Calendar.MINUTE)
    s = cal.get(Calendar.SECOND)
    totalSecs = float(m*60 + s)/3600
    x = float(h) + float(totalSecs)
    xf = x * proportionX
    
    newGeom = geom.createPoint(geom.D2, xf, yf)
    return newGeom
def main(*args):
    print "Testing graphic memory store"
    #v = DrawGraphicLayer()
    store = createMemoryStore()

    store.edit(FeatureStore.MODE_APPEND)
    f = store.createNewFeature()
    line1 = geom.createGeometry(geom.LINE)
    line1.addVertex(geom.createPoint(geom.D2, 0, 0))
    line1.addVertex(geom.createPoint(geom.D2, 10, 10))
    f.set('ID', 1)
    f.set('GEOMETRY', line1)
    store.insert(f)
    store.finishEditing()

    store.edit()
    f.set('ID', 2)
    f.set('GEOMETRY', geom.createPoint(geom.D2, 15, 10))
    store.insert(f)

    f.set('ID', 2)
    f.set('GEOMETRY', geom.createPoint(geom.D2, 15, 10))
    store.insert(f)

    store.finishEditing()

    #load layer
    mapContextManager = MapContextLocator.getMapContextManager()
    layer = mapContextManager.createLayer('MyLayer', store)
    gvsig.currentView().addLayer(layer)

    features = store.getFeatures()
    selection = store.getFeatureSelection()
    for f in features:
        selection.select(f)

    store.edit()
    features = store.getFeatureSelection()
    values = {"GEOMLINE": 1}

    for f in features:
        fe = f.getEditable()
        print "F: ", f
        for key, value in values.iteritems():
            fe.set(key, value)
        store.update(fe)
    store.commit()
 def polylineFinished(self, event):
     x = event.getXs()
     y = event.getYs()
     line = geom.createGeometry(geom.LINE, geom.D2)
     for coord in zip(x, y):
         point = geom.createPoint(geom.D2, coord[0], coord[1])
         line.addVertex(point)
     projection = self.mapControl.getProjection()
     line.setProjection(projection)
     self.quickdrawing.addGraphic(line)
     self.mapContext.invalidate()
def main(*args):
    proportionX = 1
    proportionY = 1
    xi = 0
    yi = 0
    baseLines = createBaseLayers(proportionX, proportionY)

    # Setting coordinates to aoristic clock
    nameFieldHour = "HORA"
    nameFieldDay = "DIA"
    patternHour = '%H:%M:%S'
    patternDay = '%Y-%m-%d'

    layer = gvsig.currentLayer()

    # New points layer
    schema = gvsig.createFeatureType(
        layer.getFeatureStore().getDefaultFeatureType())  # DefaultFeatureType
    newPoints = gvsig.createShape(schema)

    # Transform
    set = layer.getFeatureStore().getFeatureSet()
    newPoints.edit()
    store = newPoints.getFeatureStore()
    for f in set:
        fieldHour = f.get(nameFieldHour)
        d = datetime.datetime.strptime(fieldHour, patternHour).time()
        totalSecs = float(d.minute * 60 + d.second) / 3600
        x = float(d.hour) + float(totalSecs)
        x = x * proportionX
        fieldDay = f.get(nameFieldDay)
        dday = datetime.datetime.strptime(fieldDay, patternDay)
        y = dday.weekday()
        y = y * proportionY

        nf = store.createNewFeature(f)
        newGeom = geom.createPoint(geom.D2, x, y)
        nf.setDefaultGeometry(newGeom)
        store.insert(nf)
    newPoints.commit()
    gvsig.currentView().addLayer(newPoints)

    mp = MapContextLocator.getMapContextManager()
    leg = mp.createLegend("HeatmapLegend")
    leg.setROI(baseLines.getFullEnvelope().getGeometry())
    leg.setUseFixedViz(False)
    leg.setCorrectionFixedViz(100)
    leg.setDistance(30)
    colorTables = SymbologySwingLocator.getSwingManager().createColorTables(
    ).get(5)
    leg.setColorTable(colorTables.getColors())
    newPoints.setLegend(leg)
Exemple #5
0
def aoristicClock(store,
                  nameFieldHour,
                  nameFieldDay,
                  rangeHoursParameter,
                  rangeDaysParameter,
                  expression,
                  xi=0,
                  yi=0,
                  proportion=1,
                  selfStatus=None):
  
  i18nManager = ToolsLocator.getI18nManager()
  
  centroid = geom.createPoint(geom.D2, xi, yi)

  if rangeHoursParameter == "":
      rangeHoursParameter = "0-23"
      
  if rangeDaysParameter == "":
      rangeDaysParameter = "0-6"
      
  try:
    rangeHours = processRangeHoursParameter(rangeHoursParameter)
  except:
    rangeHours = processRangeHoursParameter("0-23")

  try:
    rangeDays = processRangeDaysParameter(rangeDaysParameter)
  except:
    rangeDays = processRangeDaysParameter("0-6")

  days = len(rangeDays)
  hours = len(rangeHours)

  internalRadius = 1*proportion
  half_step = 90
  default_segs = 15
  separationGaps = 1
  centerTopSector = False
  radiusInterval = 1*proportion
  iLabel = True
  createSectorLabel=True
  labelOnlyFirstSector = True
  dayOrderRange = [ Calendar.MONDAY,
          Calendar.TUESDAY,
          Calendar.WEDNESDAY,
          Calendar.THURSDAY,
          Calendar.FRIDAY,
          Calendar.SATURDAY,
          Calendar.SUNDAY
          ]
  
  dayNames = {Calendar.MONDAY:i18nManager.getTranslation("_Monday"),
          Calendar.TUESDAY:i18nManager.getTranslation("_Tuesday"),
          Calendar.WEDNESDAY:i18nManager.getTranslation("_Wednesday"),
          Calendar.THURSDAY:i18nManager.getTranslation("_Thursday"),
          Calendar.FRIDAY:i18nManager.getTranslation("_Friday"),
          Calendar.SATURDAY:i18nManager.getTranslation("_Saturday"),
          Calendar.SUNDAY:i18nManager.getTranslation("_Sunday")
          }

  # Prepare schema
  newSchema = gvsig.createFeatureType()
  newSchema.append("LABEL", "STRING", 20)
  newSchema.append("VALUE", "DOUBLE", 20,5)
  newSchema.append("DAY", "INTEGER", 10)
  newSchema.append("HOUR", "INTEGER", 10)
  newSchema.append("ROTATION", "DOUBLE", 10,5)
  newSchema.append("GEOMETRY", "GEOMETRY")
  newSchema.get("GEOMETRY").setGeometryType(POLYGON, D2)
  ringShape = gvsig.createShape(newSchema)

  # Point-label shape
  pointSchema = gvsig.createFeatureType(ringShape.getFeatureStore().getDefaultFeatureType())
  pointSchema.append("STRVALUE", "STRING", 20)
  pointSchema.get("GEOMETRY").setGeometryType(POINT, D2)
  pointShape = gvsig.createShape(pointSchema)
  pointStore=pointShape.getFeatureStore()
  pointShape.edit()
  
  # Vars
  ringStore = ringShape.getFeatureStore()
  ringShape.edit()

  ring_num = days
  
  step_angle = 360.0 / hours
  if centerTopSector:
    half_step = half_step + (step_angle/2) #-((default_segs*gaps)/2)

  idx_side = 0

  
  if internalRadius > 0:
    radius = internalRadius
  # Prepare radiusInterval
  if radiusInterval > 0:
      radius_interval = radiusInterval 
  else:
      radius_interval = (radius / ring_num)*proportion
  last = None
  gaps = 0
  if selfStatus!=None: selfStatus.setRangeOfValues(0,len(rangeHours))
  processText = i18nManager.getTranslation("_Processing")
  for position in range(0, len(rangeHours)): #xrange(0, hours):
    if selfStatus!=None: 
      selfStatus.setProgressText(processText + ": " + str(position)+" / "+str(int(len(rangeHours))))
      if selfStatus.isCanceled() == True:
        ringShape.finishEditing()
        return True
    i = rangeHours[position]
    if len(rangeHours)==(position+1):
      rangePosition = 0
    else:
      rangePosition = position+1
    if i != (rangeHours[rangePosition]-1):
      if i==23 and rangeHours[rangePosition]==0:
        gaps = 0
      else:
        gaps=separationGaps
    else:
      gaps=0
    correction_from_deg = (((step_angle/default_segs)*0)/2)
    correction_to_deg = (((step_angle/default_segs)*gaps)/2)
  
    from_deg = half_step - (idx_side * step_angle) - correction_from_deg
    to_deg = half_step - ((idx_side + 1) * step_angle) + correction_to_deg
    
    rin = (radius+(radius_interval*(1)))*proportion
    rout = radius*proportion
    rin, rout
    prering = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs).centroid()

    for iring, day in enumerate(rangeDays, 1): #range(0, dayOrderRange)
      #day = rangeDays[iring]
      new = ringStore.createNewFeature()
      rin = radius+(radius_interval*(iring+1))
      rout = radius+(radius_interval*iring)
      ring = create_ring_cell(centroid, from_deg, to_deg, rin, rout,  default_segs)
      #new.set("LABEL", fields[iring])
      #new.set("VALUE", feature.get(fields[iring]))
      #rotation = ((from_deg + to_deg) / 2)-90
      rotation = from_deg - 90
      if -90 < rotation < -240:
        rotation+=180
      new.set("ROTATION", rotation)
      new.set("HOUR", i)
      new.set("DAY", day)
      new.set("GEOMETRY", ring)
      ringStore.insert(new)
      if iLabel==True and labelOnlyFirstSector==True:
        pointLocation = getRingInitVertex(ring,centroid, rout,radius_interval, from_deg, proportion)
        newFeaturePoint = pointStore.createNewFeature()
        newFeaturePoint.set("LABEL", day)
        #newFeaturePoint.set("VALUE", feature.get(fields[iring]))
        newFeaturePoint.set("STRVALUE", dayNames[day])
        newFeaturePoint.set("ROTATION", rotation)
        newFeaturePoint.set("HOUR", i)
        newFeaturePoint.set("DAY", day)
        newFeaturePoint.set("GEOMETRY", pointLocation)
        pointStore.insert(newFeaturePoint)
        
    if createSectorLabel==True:
      pointLocation = getRingInitVertex(ring,centroid, rout+radius_interval,radius_interval, from_deg, proportion)
      newFeaturePoint = pointStore.createNewFeature()
      newFeaturePoint.set("LABEL", i)
      newFeaturePoint.set("VALUE", 0)
      newFeaturePoint.set("STRVALUE", " "+str(i)+":00")
      newFeaturePoint.set("ROTATION", from_deg -90)
      newFeaturePoint.set("HOUR", i)
      #newFeaturePoint.set("DAY", iring)
      newFeaturePoint.set("GEOMETRY", pointLocation)
      pointStore.insert(newFeaturePoint)
      #if gaps>0: #create anotation end of gaps time
      #  pointLocation = getRingInitVertex(ring,centroid, rout+radius_interval,radius_interval, to_deg+(1.5*correction_to_deg), 1)
      #  newFeaturePoint = pointStore.createNewFeature()
      #  newFeaturePoint.set("LABEL", i)
      #  newFeaturePoint.set("VALUE", 0)
      #  newFeaturePoint.set("STRVALUE", " "+str(i+1)+":00")
      #  newFeaturePoint.set("ROTATION", (to_deg+(1.5*correction_to_deg))-90)
      #  newFeaturePoint.set("HOUR", i)
      #  #newFeaturePoint.set("DAY", iring)
      #  newFeaturePoint.set("GEOMETRY", pointLocation)
      #  pointStore.insert(newFeaturePoint)
    if labelOnlyFirstSector:
      labelOnlyFirstSector = False
    idx_side  += 1
  ringShape.commit()

  ###
  ### GET VALUES
  ###
  if store.getSelection().getSize()!=0:
    fset = store.getSelection()
  elif (expression!=None and not expression.isEmpty()): #.getPhrase() != '':
    evaluator = DALLocator.getDataManager().createExpresion(expression)
    #evaluator = expressionEvaluatorManager.createEvaluator(expression)
    fq = store.createFeatureQuery()
    fq.addFilter(evaluator)
    fq.retrievesAllAttributes()
    fset = store.getFeatureSet(fq)
  else:
    fset = store.getFeatureSet()
 
  ###
  ### INIT DICT 
  ###
  
  dictValues = {}
  for d in dayOrderRange:
    dictHour={}
    for h in range(0,24):
      dictHour[h] = 0
    dictValues[d] = dictHour

  ###
  ### FILL DICT
  ###
  for f in fset:
    dateFieldHour = f.get(nameFieldHour) #getFieldAsDate(f.get(nameFieldHour), patternHour)
    dateFieldDay = f.get(nameFieldDay) #getFieldAsDate(f.get(nameFieldDay), patternDay)
    
    if isinstance(dateFieldDay, Date) and isinstance(dateFieldHour, Date):
      cal = Calendar.getInstance()
      cal.setTime(dateFieldDay)
      day = cal.get(Calendar.DAY_OF_WEEK)
      cal = Calendar.getInstance()
      cal.setTime(dateFieldHour)
      hour = cal.get(Calendar.HOUR_OF_DAY)
      dictValues[day][hour] += 1
  
  ###
  ### FILL SHAPE WITH VALUES
  ###
  ringShape.edit()
  store = ringShape.getFeatureStore()
  fset = store.getFeatureSet()
  for f in fset:
    e = f.getEditable()
    h = f.get("HOUR")
    d = f.get("DAY")
    e.set("VALUE", dictValues[d][h])
    fset.update(e)
  
  ###
  ### FINISH
  ###
  ringShape.commit()
  ringShape.setName("Ao-Clock")
  pointShape.commit()
  pointShape.setName("Ao-Label")
  gvsig.currentView().addLayer(ringShape)
  gvsig.currentView().addLayer(pointShape)

  ###
  ### LEGEND AND LABELS
  ###
  try:
    vil = VectorialIntervalLegend(POLYGON)
    vil.setStartColor(Color.green)
    vil.setEndColor(Color.red)
    vil.setIntervalType(1)
    ii = vil.calculateIntervals(ringShape.getFeatureStore(), "VALUE", 5, POLYGON)
    
    vil.setIntervals(ii)
    vil.setClassifyingFieldTypes([7])
    ringShape.setLegend(vil)
  except:
    pass
  
  ds = LabelingFactory().createDefaultStrategy(pointShape)
  ds.setTextField("STRVALUE")
  ds.setRotationField("ROTATION")
  ds.setFixedSize(20)
  pointShape.setLabelingStrategy(ds)
  pointShape.setIsLabeled(True)
  
  leg = SingleSymbolLegend()
  leg.setShapeType(geom.POINT)
  manager = leg.getSymbolManager()
  pointSymbol = manager.createSymbol(geom.POINT)
  pointSymbol.setColor(Color.black)
  pointSymbol.setSize(0)
  leg.setDefaultSymbol(pointSymbol)
  pointShape.setLegend(leg)
  return True
def createBaseLayers(proportionX=1, proportionY=1):

    schema = gvsig.createFeatureType()  # DefaultFeatureType
    schema.append("GEOMETRY", "GEOMETRY")
    schema.get("GEOMETRY").setGeometryType(geom.LINE, geom.D2)
    baseLines = gvsig.createShape(schema)

    schema = gvsig.createFeatureType()  # DefaultFeatureType
    schema.append("LABEL", "STRING", 20)
    schema.append("GEOMETRY", "GEOMETRY")
    schema.get("GEOMETRY").setGeometryType(geom.POINT, geom.D2)
    basePoints = gvsig.createShape(schema)
    days = {
        0: "Monday",
        1: "Tuesday",
        2: "Wednesday",
        3: "Thursday",
        4: "Friday",
        5: "Saturday",
        6: "Sunday"
    }

    # Y axis: Days

    numberDays = 7
    numberHours = 24

    for k in range(0, numberHours + 1):
        line = geom.createGeometry(geom.LINE)
        for i in range(0, numberDays):
            x = proportionX * k
            y = proportionY * i
            point = geom.createPoint(geom.D2, x, y)
            line.addVertex(point)
            if i == numberDays - 1:
                x = x
                y = y + 0.2
                point = geom.createPoint(geom.D2, x, y)
                basePoints.append({"LABEL": k, "GEOMETRY": point})

        baseLines.append({"GEOMETRY": line})

    # X axis: Days
    numberDays = 7
    numberHours = 24

    for i in range(0, numberDays):
        line = geom.createGeometry(geom.LINE)
        x = 0
        y = proportionY * i
        point = geom.createPoint(geom.D2, x, y)
        line.addVertex(point)

        x = proportionX * numberHours
        point = geom.createPoint(geom.D2, x, y)
        line.addVertex(point)

        baseLines.append({"GEOMETRY": line})

        x = -2.5
        y = y - 0.2
        point = geom.createPoint(geom.D2, x, y)
        basePoints.append({"LABEL": days[i], "GEOMETRY": point})

    # Commits
    basePoints.commit()
    baseLines.commit()

    # Labels and legends
    ds = LabelingFactory().createDefaultStrategy(basePoints)

    ds.setTextField("LABEL")
    ds.setFixedSize(20)
    basePoints.setLabelingStrategy(ds)
    basePoints.setIsLabeled(True)

    leg = SingleSymbolLegend()
    leg.setShapeType(geom.POINT)
    manager = leg.getSymbolManager()
    pointSymbol = manager.createSymbol(geom.POINT)
    pointSymbol.setColor(Color.black)
    pointSymbol.setSize(0)
    leg.setDefaultSymbol(pointSymbol)
    basePoints.setLegend(leg)

    leg = SingleSymbolLegend()
    leg.setShapeType(geom.LINE)
    manager = leg.getSymbolManager()
    newline = manager.createSymbol(geom.LINE)
    newline.setColor(Color.black)
    leg.setDefaultSymbol(newline)
    baseLines.setLegend(leg)

    gvsig.currentView().addLayer(basePoints)
    gvsig.currentView().addLayer(baseLines)
    return baseLines
def pointDensityGrid_hexa(self, lado, store, output, rotate, addEmptyGrids, projection, envelope, filterExpression, geomName):
  deltaX=lado*0.0000001
  deltaY=lado*0.0000001
  if store.getSelection().getSize()==0:
    featuresLayer = store.getFeatureSet()
  else:
    featuresLayer = store.getSelection()
  totalSize = float(featuresLayer.getSize())
  if envelope==None:
      envelope=store.getEnvelope()
  #infX = envelope.getLowerCorner().getX()-deltaX
  #infY = envelope.getLowerCorner().getY()-deltaY
  #supX = envelope.getUpperCorner().getX()+deltaX
  #supY = envelope.getUpperCorner().getY()+deltaY
  infX = envelope.getMinX()-deltaX
  infY = envelope.getMinY()-deltaY
  supX = envelope.getMaxX()+deltaX
  supY = envelope.getMaxY()+deltaY
  
  dX = supX - infX
  dY = supY - infY
  
  id_=0
  n = 0
  #sef = SpatialEvaluatorsFactory.getInstance()
  fq = store.createFeatureQuery()

  if rotate: #
    start = time.time()
    #print "Time..: ", start - time.time()
    increY = lado*0.5
    increX = (pow((pow(lado,2)-pow(lado*0.5,2)),0.5))
    numero_filas=int(dY/(lado*1.5))+2
    numero_columnas=int(dX/(increX*2))+2
    self.setRangeOfValues(0,int(numero_filas*numero_columnas))
    for i in range(0, numero_columnas):
      for j in range(0, numero_filas):
        if self.isCanceled():
          break
        else:
          self.setCurValue(n)
          n+=1
          self.setProgressText("Processing "+str(n)+" in "+str(int(numero_filas*numero_columnas))+" features")
        cX = infX + 2*increX*i
        cY = infY + 1.5*lado*j
        if j%2!=0:
          cX=cX-increX
        p1 = geom.createPoint(geom.D2, cX-increX, cY-increY)
        p2 = geom.createPoint(geom.D2, cX-increX, cY+increY)
        p3 = geom.createPoint(geom.D2, cX, cY+lado)
        p4 = geom.createPoint(geom.D2, cX+increX, cY+increY)
        p5 = geom.createPoint(geom.D2, cX+increX, cY-increY)
        p6 = geom.createPoint(geom.D2, cX, cY-lado)
        hexa = geom.createPolygon(vertexes=[p1,p2,p3,p4,p5,p6,p1])
        hexa.setProjection(projection)
  
        fs = getFeatureSetForGeoprocess(store, filterExpression, hexa, geomName)

        #start = time.time()
        count= fs.getSize()
        #print "Time..after: ", time.time() -  start
        
        if addEmptyGrids==False and count==0:
          continue
        newFeature = output.createNewFeature()
        newFeature["ID"]=id_
        newFeature["GEOMETRY"]=hexa
        newFeature["TOTAL"]=totalSize
        newFeature["COUNT"]=count
        newFeature["PERC"]=(count/totalSize)*100

        output.insert(newFeature)
        id_+=1
        
  else:
      increX = lado*0.5
      increY = (pow((pow(lado,2)-pow(lado*0.5,2)),0.5))
      numero_filas=int(dY/(increY*2))+1
      numero_columnas=int(dX/(lado*1.5))+2
  
      #Coordenadas del centro del 1er hexagono
      c1X = infX + increX
      c1Y = infY + increY
  
      numero_filas+=1
      self.setRangeOfValues(0,int(numero_filas*numero_columnas))
      for i in range(0, numero_columnas):
          if i%2 == 0:
              numero_filas-=1
          else:
              numero_filas+=1 #
          for j in range(0, numero_filas):
              if self.isCanceled():
                break
              else:
                self.setCurValue(n)
                n+=1
                self.setProgressText("Processing "+str(n)+" in "+str(int(numero_filas*numero_columnas))+" features")
              if i%2 == 0:
                  cX = c1X + (lado*1.5)*i
                  cY = c1Y + 2*increY*j
              else:
                  cX = c1X + (lado*1.5)*i
                  cY = c1Y + 2*increY*j - increY
              p1 = geom.createPoint(geom.D2, cX-increX, cY-increY)
              p2 = geom.createPoint(geom.D2, cX-lado, cY)
              p3 = geom.createPoint(geom.D2, cX-increX, cY+increY)
              p4 = geom.createPoint(geom.D2, cX+increX, cY+increY)
              p5 = geom.createPoint(geom.D2, cX+lado, cY)
              p6 = geom.createPoint(geom.D2, cX+increX, cY-increY)
              hexa = geom.createPolygon(vertexes=[p1,p2,p3,p4,p5,p6,p1])
              hexa.setProjection(projection)
              
              fs = getFeatureSetForGeoprocess(store, filterExpression, hexa, geomName)
              
              count = 0
              for k in fs:
                  if k.getDefaultGeometry().intersects(hexa):
                      count += 1
              if addEmptyGrids==False and count==0:
                continue
              newFeature = output.createNewFeature()
              newFeature["ID"]=id_
              newFeature["GEOMETRY"]=hexa
              newFeature["TOTAL"]=totalSize
              newFeature["COUNT"]=count
              newFeature["PERC"]=(count/totalSize)*100
              output.insert(newFeature)
              id_+=1
def pointDensityGrid_square(self, lado, store, output, addEmptyGrids,
                            projection, envelope, filterExpression,
                            geomFieldName):
    deltaX = lado * 0.2
    deltaY = lado * 0.2
    ###
    ### Selection
    ###
    if store.getSelection().getSize() == 0:
        featuresLayer = store.getFeatureSet()
    else:
        featuresLayer = store.getSelection()
    totalSize = float(featuresLayer.getSize())
    #TODO Adjust grid to selection

    ###
    ### ENVELOPE
    ###
    #env = self.getAnalysisExtent().getAsJTSGeometry().getEnvelopeInternal()
    if envelope == None:
        envelope = store.getEnvelope()

    infX = envelope.getMinX() - deltaX
    infY = envelope.getMinY() - deltaY
    supX = envelope.getMaxX() + deltaX
    supY = envelope.getMaxY() + deltaY

    dX = supX - infX
    dY = supY - infY

    id_ = 0

    increY = lado
    increX = lado
    #pdb.set_trace()
    numero_filas = dY / lado
    numero_columnas = dX / lado

    self.setRangeOfValues(0, int(numero_filas * numero_columnas))
    self.setProgressText("Processing " +
                         str(int(numero_filas * numero_columnas)) +
                         " features")
    n = 0
    #expandedFeatureType = createGroupyByFeatureType(store)

    for i in range(0, int(numero_columnas) + 1):
        for j in range(0, int(numero_filas) + 1):
            if self.isCanceled():
                break
            else:
                self.setCurValue(n)
                n += 1
                self.setProgressText("Processing " + str(n) + " in " +
                                     str(int(numero_filas * numero_columnas)) +
                                     " features")
            cX = infX + increX * i  #2*increX*i
            cY = infY + increY * j  #1.5*lado*j
            p1 = geom.createPoint(geom.D2, cX, cY)
            p2 = geom.createPoint(geom.D2, cX + increX, cY)
            p3 = geom.createPoint(geom.D2, cX + increX, cY + increY)
            p4 = geom.createPoint(geom.D2, cX, cY + increY)
            square = geom.createPolygon(vertexes=[p1, p2, p3, p4, p1])
            square.setProjection(projection)

            fs = getFeatureSetForGeoprocess(store, filterExpression, square,
                                            geomFieldName)

            count = fs.getSize()

            if addEmptyGrids == False and count == 0:
                continue
            newFeature = output.createNewFeature()
            newFeature["ID"] = id_
            newFeature["GEOMETRY"] = square
            newFeature["COUNT"] = count
            newFeature["PERC"] = (count / totalSize) * 100
            newFeature["TOTAL"] = totalSize
            #value = 0
            #newFeature["VALUE"]=value
            output.insert(newFeature)
            id_ += 1