def btnAdd_click(self, *args):
     model = self.lstValues.getModel()
     index = self.lstValues.getModel().getSize()
     item = inputbox("Item",
                     getTitle(),
                     messageType=QUESTION,
                     initialValue="item %s" % index)
     model.addElement(item)
Beispiel #2
0
 def btnAddCapturedPoint_click(self, event):
     if not self.__tablemodel.isPointStorageAvailable():
         return
     i18n = ToolsLocator.getI18nManager()
     pointName = inputbox(i18n.getTranslation("_Point_name"),
                          getTitle(),
                          messageType=QUESTION,
                          initialValue="")
     if pointName in ("", None):
         return
     self.__tablemodel.addPoint(pointName, self.lastPoint)
Beispiel #3
0
 def btnAdd_click(self, *args):
     model = self.lstValues.getModel()
     index = model.getSize() + 1
     item = inputbox("Item",
                     getTitle(),
                     messageType=QUESTION,
                     initialValue="item %s" % index)
     if item == None:
         return
     model.addElement(item)
     self.form.fetchValuesFromSubcombo()
Beispiel #4
0
 def btnAdd_click(self, *args):
     model = self.lstValues.getModel()
     index = model.getSize() + 1
     item = inputbox("Item",
                     getTitle(),
                     messageType=QUESTION,
                     initialValue="item %s" % index)
     if item == None:
         return
     newItem = ItemWithSubitems(item)
     model.addElement(newItem)
     self.lstValues.setSelectedIndex(index - 1)
     self.form.putValuesInSubcombo()
Beispiel #5
0
 def btnFormRename_click(self, *args):
     i18n = ToolsLocator.getI18nManager()
     index = self.cboForms.getSelectedIndex()
     if index < 0:
         return
     formName = inputbox(i18n.getTranslation("_Form_name"),
                         getTitle(),
                         messageType=QUESTION,
                         initialValue=self.__currentForm.getName())
     if formName == None:
         return
     self.__currentSection[index].setName(formName)
     self.updateSectionFromUI()
     self.cboForms.setSelectedIndex(index)
Beispiel #6
0
 def btnFormAdd_click(self, *args):
     i18n = ToolsLocator.getI18nManager()
     if self.__currentForm == None:
         index = 0
     else:
         index = len(self.__currentSection)
     formName = inputbox(i18n.getTranslation("_Form_name"),
                         getTitle(),
                         messageType=QUESTION,
                         initialValue=i18n.getTranslation("_Form_%s") %
                         index)
     if formName == None:
         return
     form = Form(formName)
     self.__currentSection.append(form)
     self.updateSectionFromUI()
     self.cboForms.setSelectedIndex(len(self.__currentSection) - 1)
Beispiel #7
0
 def btnSectionAdd_click(self, *args):
     i18n = ToolsLocator.getI18nManager()
     if self.__currentSection == None:
         index = 0
     else:
         index = len(self.__sections)
     name = inputbox(i18n.getTranslation("_Section_name"),
                     getTitle(),
                     messageType=QUESTION,
                     initialValue=i18n.getTranslation("_Section_%s") %
                     index)
     if name == None:
         return
     section = Section(name)
     self.__sections.append(section)
     self.updateSectionFromUI()
     self.cboSections.setSelectedIndex(len(self.__sections) - 1)
Beispiel #8
0
 def btnRenameSelectedPoint_click(self, event):
     if not self.__tablemodel.isPointStorageAvailable():
         return
     row = self.tblPoints.getSelectedRow()
     if row < 0:
         return
     i18n = ToolsLocator.getI18nManager()
     pointName = self.__tablemodel.getNameOfRow(row)
     if pointName == None:
         msgbox(i18n.getTranslation("_Cant_rename_point_of_selected_row"))
         return
     pointName = inputbox(i18n.getTranslation("_Point_name"),
                          getTitle(),
                          messageType=QUESTION,
                          initialValue=pointName)
     if pointName in ("", None):
         return
     self.__tablemodel.setNameOfRow(row, pointName)
    def execute(self, rule, line, parameters):
        #TopologyRule rule, TopologyReportLine line, DynObject parameters
        try:

            #logger("2", LOGGER_INFO)
            dataSet = rule.getDataSet1()

            while True:
                try:
                    d = float(
                        commonsdialog.inputbox("Enter a distance",
                                               title="",
                                               messageType=IDEA,
                                               initialValue="",
                                               root=None))
                    print "Dialog box: ", d
                    if d == 0:
                        print "entra en d=0"
                        envelope = dataSet.getFeatureStore().getEnvelope()

                        if envelope is not None or not envelope.isEmpty():
                            print "entra en if del envelope"
                            d = envelope.getLowerCorner().distance(
                                envelope.getUpperCorner())
                            print d
                        else:
                            print "entra al else del raise"
                            raise Throwable("Not valid envelope")
                    break
                except ValueError:
                    print("The entered values are not correct. Try again")

            vertexError = geom.createGeometryFromWKT(line.getData())
            print vertexError

            reference = line.getFeature1()
            feature1 = reference.getFeature()
            lineToSnap = feature1.getDefaultGeometry()

            geoManager = GeometryLocator.getGeometryManager()
            subtype = lineToSnap.getGeometryType().getSubType()
            snappedLine = geoManager.createLine(subtype)

            numVertex = lineToSnap.getNumVertices()

            store = dataSet.getFeatureStore()
            features = store.getFeatureSet()

            distance = float('inf')
            for feature in features:
                otherLine = feature.getDefaultGeometry()
                print feature.Name

                if not vertexError.intersects(otherLine):
                    dist = vertexError.distance(otherLine)

                    if dist < distance:
                        distance = dist
                        geoNearest = otherLine
                        featureToEdit = feature
                        print distance
                        geoName = feature.Name

            print "nearest geometry ", geoName

            numVertexOtherLine = geoNearest.getNumVertices()
            print numVertexOtherLine

            def segmentNearest(geometry, numVertexLine):
                disToSegment = float('inf')
                for i in range(0, numVertexLine - 1):
                    print "index ", i
                    vertex1 = geometry.getVertex(i)
                    vertex2 = geometry.getVertex(i + 1)
                    segment = geoManager.createLine(subtype)
                    segment.addVertex(vertex1)
                    segment.addVertex(vertex2)
                    print segment.getNumVertices()

                    dToSegment = vertexError.distance(segment)

                    if dToSegment < disToSegment:
                        disToSegment = dToSegment
                        segmentNearest = segment
                        numSegment = i + 1
                        print disToSegment

                return disToSegment, segmentNearest

            #disToSegment = float('inf')
            if GeometryUtils.isSubtype(geom.MULTICURVE,
                                       geoNearest.getGeometryType().getType()):
                for x in range(0, geoNearest.getNumPrimitives()):
                    geox = geoNearest.getPrimitiveAt(x)
                    numVertexMulti = geox.getNumVertices()
                    disToSegment, segmentNearest = segmentNearest(
                        geox, numVertexMulti)
            else:
                disToSegment, segmentNearest = segmentNearest(
                    geoNearest, numVertexOtherLine)

            #print "Segment nearest is ", numSegment
            print "Distance nearest to segment is ", disToSegment

            dToVertex1 = vertexError.distance(segmentNearest.getVertex(0))
            print "dToVertex1 ", dToVertex1
            dToVertex2 = vertexError.distance(segmentNearest.getVertex(1))
            print "dToVertex2 ", dToVertex2

            perpendicular = False

            if dToVertex1 < d or dToVertex2 < d:
                if dToVertex1 < dToVertex2:
                    vertex = segmentNearest.getVertex(0)
                    print "vertex 1"
                elif dToVertex1 > dToVertex2:
                    vertex = segmentNearest.getVertex(1)
                    print "vertex 2"
                elif dToVertex1 == dToVertex2:
                    vertex = segmentNearest.getVertex(0)
                    print "vertex 1"
            elif disToSegment < d:
                perpendicular = True
                print "perpendicular"

                Iy = segmentNearest.getVertex(
                    1).getY() - segmentNearest.getVertex(0).getY()
                Ix = segmentNearest.getVertex(
                    1).getX() - segmentNearest.getVertex(0).getX()

                if Ix == 0:
                    slope1 = float('inf')
                else:
                    slope1 = Iy / Ix

                b1 = segmentNearest.getVertex(
                    0).getY() - slope1 * segmentNearest.getVertex(0).getX()
                print "straight line 1"
                print slope1, b1

                if slope1 == 0:
                    slope2 = float('-inf')
                else:
                    slope2 = -(1 / slope1)

                b2 = vertexError.getY() - slope2 * vertexError.getX()

                print "straight line 2"
                print slope2, b2

                x = (b2 - b1) / (slope1 - slope2)
                if math.isnan(x):
                    if slope1 == 0:
                        x = vertexError.getX()
                    elif slope1 == float('inf'):
                        x = segmentNearest.getVertex(0).getX()
                print "x", x
                y = slope1 * x + b1
                if math.isnan(y):
                    y = vertexError.getY()
                print "y", y

                vertex = createPoint(subtype, x, y)
                print vertex

            else:
                vertex = None

            if vertex != None:
                if lineToSnap.getVertex(0) == vertexError:
                    print "start"
                    #      if typeLine == "start":
                    snappedLine.addVertex(vertex)

                for i in range(0, numVertex):
                    print i
                    if lineToSnap.getVertex(i) == vertexError:
                        print "continue"
                        continue
                    else:
                        print "else"
                        snappedLine.addVertex(lineToSnap.getVertex(i))
                        print snappedLine.getNumVertices()

                if lineToSnap.getVertex(numVertex - 1) == vertexError:
                    print "end"
                    #      if typeLine == "end":
                    snappedLine.addVertex(vertex)

                #print "update lineToSnap"
                #feature1 = feature1.getEditable()
                #feature1.set("GEOMETRY", snappedLine)
                #dataSet.update(feature1)

                if perpendicular == True:
                    subtype = geoNearest.getGeometryType().getSubType()
                    intersectedLine = geoManager.createLine(subtype)
                    for i in range(0, geoNearest.getNumVertices() - 1):
                        vertex1 = geoNearest.getVertex(i)
                        vertex2 = geoNearest.getVertex(i + 1)
                        segment = geoManager.createLine(subtype)
                        segment.addVertex(vertex1)
                        segment.addVertex(vertex2)
                        print segment.getNumVertices()

                        if vertex.intersects(segment):
                            print "intersecta"
                            intersectedLine.addVertex(vertex1)
                            intersectedLine.addVertex(vertex)
                            intersectedLine.addVertex(vertex2)
                        else:
                            print "no intersecta"
                            intersectedLine.addVertex(vertex1)
                            intersectedLine.addVertex(vertex2)

                    print "update intersectedLine"
                    print intersectedLine.getNumVertices()
                    featureToEdit = featureToEdit.getEditable()
                    featureToEdit.set("GEOMETRY", intersectedLine)
                    dataSet.update(featureToEdit)

                print "update lineToSnap"
                feature1 = feature1.getEditable()
                feature1.set("GEOMETRY", snappedLine)
                dataSet.update(feature1)

            else:
                print "It can't snap"

        except:
            ex = sys.exc_info()[1]
            print "Error", ex.__class__.__name__, str(ex)
def calcularArea(currentView, currentLayer):

    # Ejemplo de inputbox
    message = "Ingrese el valor del " + unichr(
        225) + "rea de referencia en km2"
    title = "Ingreso de datos"
    messageType = commonsdialog.QUESTION
    root = None

    currentProject = gvsig.currentProject()  # Proyecto actual
    # Vista actual
    print "Vista actual:", currentView
    # Capas
    print "Capas de la vista actual:"
    if currentView != None:
        currentViewLayers = currentView.getLayers()
        for currentViewLayer in currentViewLayers:
            print " ", currentViewLayer
    # Capa actual
    print "Sumatory of all of the areas in the polygon layer: ", currentLayer

    valorReferencia = float(
        commonsdialog.inputbox(message, title, messageType, root))
    print "valor Referencia: ", valorReferencia

    area = 0
    if currentView != None:
        if currentLayer != None:
            polygonsLayer = currentLayer
            # Creamos esquema con el tipo de geometria correspondiente
            schema = polygonsLayer.getSchema()
            newSchema = createSchema(schema)
            # Creamos la capa nueva con el nuevo esquema
            newPolygonsLayer = createShape(newSchema)
            newPolygonsLayer.edit()

            features = currentLayer.features()  # Entidades
            message = ""
            if features != None:
                try:
                    polygonFeatures = polygonsLayer.features()
                    contador = 0
                    for polygonFeature in polygonFeatures:
                        area += polygonFeature.geometry().area()
                        #print("area: ",area)
                        polygon = dict()
                        for field in schema:
                            #print "prueba: "+str(field.getDataTypeName())
                            if str(field.getDataTypeName()) != "Double":
                                polygon[field.getName()] = polygonFeature.get(
                                    field.getName())
                            else:
                                polygon[field.getName()] = long(
                                    polygonFeature.get(field.getName()))

                        tempArea = polygonFeature.geometry().area() * 1000

                        if tempArea > valorReferencia:
                            newPolygonsLayer.append(polygon)
                            contador = contador + 1
                            #newfeature = self.createNewFeature(output_store, polygonFeature)
                            #newfeature["GEOMETRY"] = polygon
                            #output_store.insert(newfeature)

                    area = area * 10000  # area *10000 para obtener el area en kilometros cuadrados
                    #self.addOutputText("OutputText", "Area: ")
                    #self.addOutputNumericalValue("OutputNumerical", "area")
                    newPolygonsLayer.commit()
                    newPolygonsLayer.setName("Capa de poligonos mayores")
                    currentView.addLayer(newPolygonsLayer)
                except:
                    ex = sys.exc_info()[1]  # Captura de excepciones
                    message = ex.__class__.__name__ + " - " + str(ex)
                finally:
                    DisposeUtils.disposeQuietly(
                        features)  # Liberacion de recursos
            if message != "":
                title = "Error"
                messageType = commonsdialog.FORBIDEN
                root = None
                commonsdialog.msgbox(message, title, messageType, root)
        else:
            mensajeCartel(
                "En la vista actual no hay seleccionada ninguna capa, debe seleccionar una capa.",
                "Error: se debe seleccionar una capa", commonsdialog.FORBIDEN)
    else:
        mensajeCartel("No se encuentra ninguna vista para comenzar a trabajar",
                      "Error: sin vista", commonsdialog.FORBIDEN)

    return area
Beispiel #11
0
    def execute(self, rule, line, parameters):
        #TopologyRule rule, TopologyReportLine line, DynObject parameters
        try:

            dataSet = rule.getDataSet1()

            while True:
                try:
                    d = float(
                        commonsdialog.inputbox("Enter a distance",
                                               title="",
                                               messageType=IDEA,
                                               initialValue="",
                                               root=None))
                    if d == 0:
                        envelope = dataSet.getFeatureStore().getEnvelope()

                        if envelope is not None or not envelope.isEmpty():
                            d = envelope.getLowerCorner().distance(
                                envelope.getUpperCorner())
                        else:
                            raise Throwable("Not valid envelope")
                    break
                except ValueError:
                    print("The entered values are not correct. Try again")

            vertexError = geom.createGeometryFromWKT(line.getData())

            reference = line.getFeature1()
            feature1 = reference.getFeature()
            lineToTrim = feature1.getDefaultGeometry()

            geoManager = GeometryLocator.getGeometryManager()
            subtype = lineToTrim.getGeometryType().getSubType()
            trimmedLine = geoManager.createLine(subtype)

            numVertex = lineToTrim.getNumVertices()

            store = dataSet.getFeatureStore()
            features = store.getFeatureSet()

            distance = float('inf')
            for feature in features:
                otherLine = feature.getDefaultGeometry()
                print feature.Name

                if (lineToTrim.intersects(otherLine)
                        and not lineToTrim.equals(otherLine)):
                    iP = lineToTrim.intersection(otherLine)
                    dist = vertexError.distance(iP)

                    if dist < distance:
                        distance = dist
                        intersectionPoint = iP

            print "final intersection ", intersectionPoint

            if lineToTrim.getVertex(0) == vertexError:
                #typeLine == "start"
                trimmedLine.addVertex(intersectionPoint)

            for i in range(0, numVertex):
                if lineToTrim.getVertex(i) == vertexError:
                    continue
                else:
                    trimmedLine.addVertex(lineToTrim.getVertex(i))

            if lineToTrim.getVertex(numVertex - 1) == vertexError:
                #typeLine == "end"
                trimmedLine.addVertex(intersectionPoint)

            feature1 = feature1.getEditable()
            feature1.set("GEOMETRY", trimmedLine)
            dataSet.update(feature1)

        except:
            ex = sys.exc_info()[1]
            print "Error", ex.__class__.__name__, str(ex)
Beispiel #12
0
    def execute(self, rule, line, parameters):
        #TopologyRule rule, TopologyReportLine line, DynObject parameters
        try:

            dataSet = rule.getDataSet1()

            while True:
                try:
                    d = float(
                        commonsdialog.inputbox("Enter a distance",
                                               title="",
                                               messageType=IDEA,
                                               initialValue="",
                                               root=None))
                    if d == 0:
                        envelope = dataSet.getFeatureStore().getEnvelope()

                        if envelope is not None or not envelope.isEmpty():
                            d = envelope.getLowerCorner().distance(
                                envelope.getUpperCorner())
                        else:
                            raise Throwable("Not valid envelope")
                    break
                except ValueError:
                    print("The entered values are not correct. Try again")

            vertexError = geom.createGeometryFromWKT(line.getData())
            print vertexError

            reference = line.getFeature1()
            feature1 = reference.getFeature()
            lineToExtend = feature1.getDefaultGeometry()

            geoManager = GeometryLocator.getGeometryManager()
            subtype = lineToExtend.getGeometryType().getSubType()
            extendedLine = geoManager.createLine(subtype)

            numVertex = lineToExtend.getNumVertices()

            if lineToExtend.getVertex(0) == vertexError:
                typeLine = "start"
                Iy = -(lineToExtend.getVertex(1).getY() -
                       lineToExtend.getVertex(0).getY())
                Ix = -(lineToExtend.getVertex(1).getX() -
                       lineToExtend.getVertex(0).getX())
            else:
                typeLine = "end"
                Iy = lineToExtend.getVertex(numVertex - 1).getY(
                ) - lineToExtend.getVertex(numVertex - 2).getY()
                Ix = lineToExtend.getVertex(numVertex - 1).getX(
                ) - lineToExtend.getVertex(numVertex - 2).getX()

            if Ix == 0 or Ix == -0:
                if Iy > 0:
                    slope = float('inf')
                else:
                    slope = float('-inf')
            else:
                slope = Iy / Ix

            if slope > 0:
                if Iy > 0:
                    ang = math.degrees(math.atan(slope))
                else:
                    ang = math.degrees(math.atan(slope)) + 180
            elif slope < 0:
                if Iy > 0:
                    ang = math.degrees(math.atan(slope)) + 180
                else:
                    ang = math.degrees(math.atan(slope)) + 360
            elif slope == 0:
                if Ix > 0:
                    ang = math.degrees(math.atan(slope))
                else:
                    ang = math.degrees(math.atan(slope)) + 180
            elif slope == float('inf'):
                ang = math.degrees(math.atan(slope))
            elif slope == float('-inf'):
                ang = math.degrees(math.atan(slope)) + 360
            print ang

            vertex = createPoint(
                subtype,
                vertexError.getX() + d * math.cos(math.radians(ang)),
                vertexError.getY() + d * math.sin(math.radians(ang)))
            print vertex

            segment = geoManager.createLine(subtype)
            segment.addVertex(vertexError)
            segment.addVertex(vertex)

            store = dataSet.getFeatureStore()
            features = store.getFeatureSet()

            distance = float('inf')
            for feature in features:
                otherLine = feature.getDefaultGeometry()
                print feature.Name

                if (segment.intersects(otherLine)
                        and not vertexError.intersects(otherLine)):
                    iP = segment.intersection(otherLine)
                    dist = vertexError.distance(otherLine)

                    if dist < distance:
                        distance = dist
                        intersectionPoint = iP

            print "final intersection ", intersectionPoint

            if typeLine == "start":
                extendedLine.addVertex(intersectionPoint)

            for i in range(0, numVertex):
                extendedLine.addVertex(lineToExtend.getVertex(i))

            if typeLine == "end":
                extendedLine.addVertex(intersectionPoint)

            feature1 = feature1.getEditable()
            feature1.set("GEOMETRY", extendedLine)
            dataSet.update(feature1)

        except:
            ex = sys.exc_info()[1]
            print "Error", ex.__class__.__name__, str(ex)