banniere

Le portail francophone de la géomatique


Toujours pas inscrit ? Mot de passe oublié ?
Nom d'utilisateur    Mot de passe              Toujours pas inscrit ?   Mot de passe oublié ?

Annonce

GEODATA DAYS 2024

#1 Thu 05 July 2012 12:34

FatimZB
Participant occasionnel
Date d'inscription: 26 Jun 2012
Messages: 12

[MapBasic 9.5] décalage d'insertion

Bonjour Tout le monde,
SVP j'ai deux tables : Table1 une contient les données Nom_Pivot,  Xp et Yp l'autre contient Nom_Pivot et d'autre information
mon but est de lire le nom_pivot de la table2 et d'aller chercher de la table1 le Xp et Yp correspondant à ce nom_pivot et effectuer des traitement en se basant sur des données de la table2.
J'ai fais le code suivant mais le problème est qu'il me génère un décalage au niveau de l'insertion et même si il ne trouve pas le Xp et le Yp dans la table1 il affecte quand même à Xpiv et Ypiv de la table1 une valeur .
Voici le code que j'ai fais :
//////////////////////////////////////////: Debut du code

Dim PosX as String
Dim PosY as String
Dim i as Integer
Dim DistX as Float
Dim DistY as Float

Dim NomPiv as String
Dim N_Piv as String
Dim Xc as Float
Dim Yc as Float

Dim X_Pivot as Float
Dim Y_Pivot as Float

Alter table Permis_SPivot_M ( Add Xpiv Float, Ypiv Float, Xcc Float, Ycc Float )

i=0

'boucle table sans pivot'

fetch first from permis_SPivot_M
Do While Not EOT( permis_SPivot_M )

NomPiv = permis_SPivot_M.NOM_PIVOT

DistX = permis_SPivot_M.SIT_EW
DistY = permis_SPivot_M.Sit_NS
PosX = permis_SPivot_M.E_W
PosY = permis_SPivot_M.N_S
'Deuxième boucle'

fetch first from point_pivot
Do While Not EOT ( point_pivot )

N_Piv = point_pivot.NOM_PIVOT



If N_Piv = NomPiv then

    X_Pivot = point_pivot.XP
    Y_Pivot = point_pivot.YP

    Update permis_SPivot_M
    set XPiv = X_Pivot
    Where RowID = i

    Update permis_SPivot_M
    set YPiv = Y_Pivot
    Where RowID = i

        If PosX = "E" then
        Xc = X_Pivot + DistX
        Else
        Xc = X_Pivot - DistX
        End If
   
    update permis_SPivot_M
    set Xcc = Xc
    Where RowID = i

        If PosY = "N" then
        Yc = Y_Pivot + DistY
        Else
        Yc = Y_Pivot - DistY
        End If

    update permis_SPivot_M
    set Ycc = Yc
    Where RowID = i

i=i+1



End If

Fetch Next from point_pivot
Loop



Fetch Next from permis_SPivot_M
Loop

///////////////////////////////////////////: Fin du Code

Svp toutes vos remarques et conseils me seront très utiles.

Merci d'avance pour votre interaction

Hors ligne

 

#2 Thu 05 July 2012 14:03

Damien BEAUSEIGNEUR
Participant assidu
Lieu: meyzieu
Date d'inscription: 5 Sep 2005
Messages: 425

Re: [MapBasic 9.5] décalage d'insertion

Bonjour,

personnellement je trouve ça un peut compliqué, pour ce qui peut s'écrire très simplement en sql.

première remarque: le i=i+1 n'est pas au bon endroit, il devrait être juste avant la fin de boucle portant sur permis_Spivot_M. La position du i=i+1 est la cause de l'erreur...
deuxième remarque: au niveau des updates, regroupe les modifications en une foi.

l'utilisation du rowid pour la mise à jour n'est pas forcément le plus juste, vu que tu ne récupère pas directement le rowid de ton parcours de table, l'idéal est de créer un champ unique pour chaque enregistrement pour éviter les doublons. et de sélectionner chaque enregistrement par ce champ.

cordialement

Damien

Hors ligne

 

#3 Thu 05 July 2012 14:27

FatimZB
Participant occasionnel
Date d'inscription: 26 Jun 2012
Messages: 12

Re: [MapBasic 9.5] décalage d'insertion

Bonjour,
Merci beaucoup Mr Damien pour votre interaction.
Malgré que je déplace le i=i+1 il y a tjrs un décalage mais un peu modéré.
pour votre deuxième remarque Le fait de regrouper les update ou les laisser éparpiller ne change rien au niveau du résultat.

SVP Monsieur est ce que vous pouvez mieux expliquer la solution que vous proposer à savoir la création d'un nouveau champ.. Parce que j'ai pas bien compris ce que vous voulez dire
Merci pour votre interaction.
Je suis tjrs dans l'attente de votre remarques et conseils.

Hors ligne

 

#4 Thu 05 July 2012 14:58

Damien BEAUSEIGNEUR
Participant assidu
Lieu: meyzieu
Date d'inscription: 5 Sep 2005
Messages: 425

Re: [MapBasic 9.5] décalage d'insertion

Bon je sais que la deuxième remarque c'est juste une méthode d'écriture et un meilleur traitement du code.

alors il n'y as peut-être pas besoin d'utiliser le rowid et de créer un champ index, pour créer l’équivalent d'une primary key.

Pour éviter tout problème de rowid: utilise

permis_SPivot_M.NOM_PIVOT = NomPiv


à la place du

rowid = i


c'est plus sur.

Hors ligne

 

#5 Thu 05 July 2012 15:22

FatimZB
Participant occasionnel
Date d'inscription: 26 Jun 2012
Messages: 12

Re: [MapBasic 9.5] décalage d'insertion

J'avais essayer cette syntaxe mais ça marche pas il me génère une erreur lors de la compilation sur Mapinfo
erreur :
  " le résultat de l'expression n'est pas le nom d'une colonne ou d'une table "
même lorsque j'écris  permis_SPivot_M.NOM_PIVOT = permis_pivot.NOM_PIVOT
malgré que la même syntaxe est utilisé avant la ère condition If .

Hors ligne

 

#6 Thu 05 July 2012 16:36

Damien BEAUSEIGNEUR
Participant assidu
Lieu: meyzieu
Date d'inscription: 5 Sep 2005
Messages: 425

Re: [MapBasic 9.5] décalage d'insertion

Et si tu écrivais simplement Nom_pivot = NomPiv .

dans un update tu dois utiliser la syntaxe sql et pas celle de mapbasic.
La dernière syntaxe présentée ne marchera de toute façon pas sans avoir définit dans le nom des tables de l'update permis_pivot.

Hors ligne

 

#7 Thu 05 July 2012 16:58

FatimZB
Participant occasionnel
Date d'inscription: 26 Jun 2012
Messages: 12

Re: [MapBasic 9.5] décalage d'insertion

Oui même si j utilise cette syntaxe ça marche tjrs pas :s :s :s :s

Hors ligne

 

#8 Thu 05 July 2012 22:03

Damien BEAUSEIGNEUR
Participant assidu
Lieu: meyzieu
Date d'inscription: 5 Sep 2005
Messages: 425

Re: [MapBasic 9.5] décalage d'insertion

bon j'ai vérifié l'aide,
mea culpa. !il faut bien utiliser le rowid, par contre le premier enregistrement d'une table c'est le 1 pas le 0. Donc à l'initialisation il faut avoir i = 1 et non pas i = 0.

Si ce n'est pas suffisant.
essaye de stocker dans i la valeur du rowid, à faire au en tant que première instruction de la première boucle.
i = permis_SPivot_M.rowid

Hors ligne

 

#9 Mon 09 July 2012 13:31

FatimZB
Participant occasionnel
Date d'inscription: 26 Jun 2012
Messages: 12

Re: [MapBasic 9.5] décalage d'insertion

Bonjour,
Merci beaucoup pour votre interaction je m'excuse pour ce retard qui est du essentiellement à des problèmes de connexion.
Pour la proposition j'ai procédé autrement en se basant sur des jointures et des tables intermédiaires.
Maintenant j'ai presque terminé - grave à votre aide sur les différents sujets que j'ai posté depuis que j'ai commencé à travailler sur ce sujet - mais j'ai toujours un petit problème.
je dois faire une boite de dialogue pour communiquer avec l utilisateur. sur cette boite l'utilisateur détermine à partir d'une table les champs des colonnes qui contiennent les informations utilisées pour effectuer le traitement que j'ai fais sur le code précédant.
Donc mon code doit effectuer des traitements à partir des champs k l utilisateur à attribuer à chaque variable que j'ai déclaré dans le code. Par exemple au lieu d’écrire  Numéro = Table1.Champs1 je cherche à attribuer à la variable Numéro la valeur que lui a attribué l'utilisateur par exemple strColList(4).


Include "mapbasic.def"

'
Declare Sub Main
Declare Sub FillColumnlist
Declare Sub PrintColumn
Declare Sub checker
Declare Sub Calculer_Centre

'
dim strColList()as string
dim strColList_1 as string
dim strTableList() as string
dim i as integer

'
dim intCounter,intTableid,intColumnid,intTabnum,intColnum as integer
dim strColname,strTabname as string
'
sub main
'
'Get the number of tables currently open and redimension the table array.

intTabnum = NumTables()
redim strTablelist(intTabnum)
'
'Populate the table array with the table names
for intCounter = 1 to intTabnum
strTablelist(intCounter) = TableInfo(intCounter,TAB_INFO_NAME)
next
'
'Get the number of columns in the first table and redim the column array
intColnum = NumCols(strTablelist(1))
redim strColList(intColnum)

'Populate the column array with the column names
for intCounter = 1 to intColnum
strColList(intCounter) = ColumnInfo(strTablelist(1),"COL"+intCounter,COL_INFO_NAME)
next

'initialize the intTableid variable so that it always points to a table
intTableid=1

'end program
'Create the dialog with two popupmenus and an OK button

dialog
title "CHOIX DE TABLES ET DES COLONNES DEMANDEES"


Control GroupBox
    Title "Structure_Table"
    Position 130, 5
    Width 70
    ID 11
Control RadioGroup
    Title "&Avec_Piv;&Sans_Piv"
    Value 1
    ID 10
    Position 140, 15
    Calling checker



Control StaticText
    Title "Nom_Table:"
    Position 5, 50
'
control popupmenu
    ID 1
    position 60,50
    width 200
    Height 60
    calling fillcolumnlist
    title from variable strTablelist
'
Control StaticText
    Title "Nom_Pivot:"
    Position 5, 70
'
control popupmenu
    ID 2
    Position 60,70
    width 200
    Height 60
    title from variable strColList
'
Control StaticText
    Title "Num_Permis:"
    Position 5, 90
'
control popupmenu
    ID 3
    position 60,90
    width 200
    Height 60   
    title from variable strColList
'
Control StaticText
    Title "X_Pivot:"
    Position 5, 110
'
control popupmenu
    ID 4
    position 60,110
    width 200
    Height 60
    title from variable strColList
'
Control StaticText
    Title "Y_Pivot:"
    Position 5, 130
'
Control Popupmenu
    ID 5
    Position 60, 130
    width 200
    Height 60
    title from variable strColList
'
Control StaticText
    Title "Direc_X:"
    Position 5, 150
'
Control Popupmenu
    ID 6
    Position 60,150
    width 200
    Height 60
    title from variable strColList
'
Control StaticText
    Title "Direc_Y:"
    Position 5, 170
'
Control Popupmenu
    ID 7
    Position 60,170
    width 200
    Height 60
    title from variable strColList
'   
Control StaticText
    Title "Dist_X:"
    Position 5, 190
'
Control Popupmenu
    ID 8
    Position 60,190
    width 200
    Height 60
    title from variable strColList
'
Control StaticText
    Title "Dist_Y:"
    Position 5, 210
'
Control Popupmenu
    ID 9
    Position 60,210
    width 200
    Height 60
    title from variable strColList
'
Control StaticText
    Title "Zone:"
    Position 5, 230
Control Popupmenu
    ID 12
    Position 60,230
    width 200
    Height 60
    title from variable strColList




control OKButton

Calling Calculer_Centre

Position 300, 260


Control CancelButton
Position 5, 260
end sub
'This procedure re-populates the column array with the column names in
'the table the user picked from the table popup menu.

sub fillcolumnlist
intTableid = ReadControlValue(1)
strTabname = TableInfo(strTablelist(intTableid), TAB_INFO_NAME)
intColnum = NumCols(strTabname)
'
redim strColList(intColnum)
for intCounter = 1 to intColnum
strColList(intCounter) = ColumnInfo(strTablelist(intTableid),"COL"+intCounter,COL_INFO_NAME)
next
'

'Update the column popup menu with the new column array
For i = 2 to 9
Alter Control i Title From Variable strColList

next
end sub



sub PrintColumn
'Get the name of the column the user picked and print it on screen.
for i=2 to 9
intColumnid = ReadControlValue(i)
strColname = ColumnInfo(strTablelist(intTableid),"COL"+intColumnid,COL_INFO_NAME)
print strColname
Next
end sub

Sub checker
if ReadControlValue(10) = 1 then
    Alter Control 4 Enable
    Alter Control 5 Enable
    
Else
    Alter Control 4 Disable
    Alter Control 5 Disable
End If
End Sub


Sub Calculer_Centre

Dim DIR_EST_OUEST as String
Dim DIR_NORD_SUD as String
Dim DistX as Float
Dim DistY as Float
Dim DIS_EST_OUEST as Float
Dim DIST_NORD_SUD as Float
Dim NumPermis as Float
Dim DIR_X As String
Dim DIR_Y As String
Dim Xc as Float
Dim Yc as Float
Dim ABCISSE_DU_POINT_PIVOT as Float
Dim ORDONNEE_DU_POINT_PIVOT as Float
Dim X_Pivot as Float
Dim Y_Pivot as Float
Dim Zone_Projection as Float

fetch first from Permis_noir_2010_2011_M

Do While Not EOT( Permis_noir_2010_2011_M )

NumPermis = Permis_noir_2010_2011_M.N_TITRE_MINIER
Zone_Projection = Permis_noir_2010_2011_M.ZONE

X_Pivot = Permis_noir_2010_2011_M.ABCISSE_DU_POINT_PIVOT
Y_Pivot = Permis_noir_2010_2011_M.ORDONNEE_DU_POINT_PIVOT
DistX = Permis_noir_2010_2011_M.DIS_EST_OUEST
DistY = Permis_noir_2010_2011_M.DIST_NORD_SUD

If DIR_EST_OUEST = "E" then
    Xc = X_Pivot + DistX
Else
    Xc = X_Pivot - DistX
End If

If DIR_NORD_SUD = "N" then
    Yc = Y_Pivot + DistY
Else
    Yc = Y_Pivot - DistY
End If

Insert into Table_Centres (ZoneProjection,N_Permis,X_Centre,Y_Centre) Values (Zone_Projection,NumPermis,Xc,Yc)
Fetch Next from Permis_noir_2010_2011_M
Loop


Dim X_Point as Float
Dim Y_Point as Float
Dim o_region As Object
Dim ZoneProj As Integer
Dim Num_Permi As String
Dim x(5) , y(5) as Float
Dim i as Integer



Fetch First From Table_Centres




Do While Not EOT(Table_Centres)

ZoneProj = Table_Centres.ZoneProjection

If ZoneProj = 1 then
set coordsys earth
Projection 3,55,7,-5.4,33.3,31.72786641202,34.8717272112,500000,300000
ElseIf ZoneProj = 2 then
set coordsys earth
Projection 3, 55, 7, -5.4, 29.7, 28.1063294800, 31.2932791054, 500000, 300000
ElseIf ZoneProj = 3 then
set coordsys earth
Projection 3, 55, 7, -5.4, 26.1, 24.5075340813, 27.6921073632, 1200000, 400000
Else ZoneProj = 4
set coordsys earth
Projection 3, 55, 7, -5.4, 22.5, 20.9075742561, 24.0921050540, 1500000, 400000

End If
                 
Num_Permi = Table_Centres.N_Permis
X_Point = Table_Centres.X_Centre
Y_Point = Table_Centres.Y_Centre


x(1) = X_Point + 2000
y(1) = Y_Point - 2000

x(2) = X_Point + 2000
y(2) = Y_Point + 2000

x(3) = X_Point - 2000
y(3) = Y_Point + 2000

x(4) = X_Point - 2000
y(4) = Y_Point - 2000

x(5) = x(1)
y(5) = y(1)

' First, create an empty region object
Create Region Into Variable o_region 0

' Now add nodes to populate the object:
For i = 1 to 5
Alter Object o_region Node Add ( x(i), y(i) )
Next

' Now store the object in the Sites table:
    Insert Into Table_Region (Zone_Proj,Nm_Permis,obj) Values (ZoneProj,Num_Permi,o_region)
    Fetch Next From Table_Centres
Loop

select * from Table_Region, Permis_noir_2010_2011_M
where Table_Region.Nm_Permis = Permis_noir_2010_2011_M.N_TITRE_MINIER
into Table_Region_Finale
Commit Table Table_Region_Finale As "C:\Users\hp\Desktop\Stage2012\code\Table_Region_Finale.TAB"
End Sub

Quand je remplace

NumPermis = Permis_noir_2010_2011_M.N_TITRE_MINIER

Par

NumPermis = strTableList(1).strColList(3)

Il me genere erreur unreconized command

Merci pour votre interaction .

Tout votre conseils et remarque me seront tres utiles.

Merci bcp

Dernière modification par FatimZB (Mon 09 July 2012 14:00)

Hors ligne

 

Pied de page des forums

Powered by FluxBB